Tomcat 5.5AndTomcat5.0The configurations are different., Tomcat5.5The configuration is as follows::
In Server. xml The configuration in the file is as follows: :
<Context Path = "/recommend" reloadable = "true" docbase = "C: \ eclipse \ workspace \ recommend" workdir = "C: \ eclipse \ workspace \ recommend \ work">
<Resource Name = "JDBC/myoracle" auth = "Container" type = "javax. SQL. datasource"
Maxactive = "100" maxidle = "30" maxwait = "10000"
Username = "spstest" Password = "sps0922"
Driverclassname = "oracle. JDBC. Driver. oracledriver"
Url = "JDBC: oracle: thin :@ 192.168.6.15: 1521: ora9"/>
</Context>
In C: \ Tomcat 5.5 \ common \ Lib Directory Class12.jar
Class12.jarYesOracleOfJDBCDriverProgramNo package
In Web. xml ModifyingCode
<Description> oralcedb </description>
<Resource-ref>
<Description> dB connection </description>
<Res-ref-Name> JDBC/myoracle </RES-ref-Name>
<Res-type> javax. SQL. datasource </RES-type>
<Res-auth> container </RES-auth>
</Resource-ref>
Test code
<% @ Page import = "javax. Naming. Context" %>
<% @ Page import = "javax. SQL. datasource" %>
<% @ Page import = "javax. Naming. initialcontext" %>
<% @ Page import = "Java. SQL. *" %>
<%
Datasource DS = NULL;
Context jndicntx = new initialcontext ();
DS = (datasource) jndicntx. Lookup ("Java: COMP/ENV/jdbc/myoracle ");
If (Ds! = NULL ){
System. Out. println ("connection is OK! ");
}
Else
{
System. Out. println ("connection is fail! ");
}
Connection Cn = Ds. getconnection ();
If (CN! = NULL ){
System. Out. println ("CN is OK! ");
}
Else
{
System. Out. println ("CN is fail! ");
}
// Statement stmt = cn. createstatement ();
// Resultset rst = stmt.exe cutequery ("select * from book ");
//Out. println ("<p> RST is OK! "+ RST. Next ());
//While (RST. Next ()){
//System. Out. println ("<p> book_code:" + RST. getstring (1 ));
//}
CN. Close ();
%>