高分请教 Tomcat数据库连接池的配置
lingyuhuihui
|
1#
lingyuhuihui 发表于 2007-01-18 17:05
高分请教 Tomcat数据库连接池的配置
问题:Connection is OK! org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'oracle.jdbc.driver.OracleDriver ' for connect URL 'jdbc.oracle.thin:@172.16.9.81:1521:stdw '
%TOMCAT_HOME%/conf/server.xml配置: <?xml version= '1.0 ' encoding= 'utf-8 '?> <Server> <Listener className= "org.apache.catalina.mbeans.ServerLifecycleListener "/> <Listener className= "org.apache.catalina.mbeans.GlobalResourcesLifecycleListener "/> <GlobalNamingResources> <Environment name= "simpleValue " type= "java.lang.Integer " value= "30 "/> <Resource auth= "Container " description= "User database that can be updated and saved " name= "UserDatabase " type= "org.apache.catalina.UserDatabase "/> <Resource name= "jdbc/testDB " auth= "Container " type= "javax.sql.DataSource " override= "false "/> <ResourceParams name= "UserDatabase "> <parameter> <name> factory </name> <value> org.apache.catalina.users.MemoryUserDatabaseFactory </value> </parameter> <parameter> <name> pathname </name> <value> conf/tomcat-users.xml </value> </parameter> </ResourceParams> <ResourceParams name= "jdbc/testDB "> <parameter> <name> factory </name> <value> org.apache.commons.dbcp.BasicDataSourceFactory </value> </parameter> <parameter> <name> url </name> <value> jdbc.oracle.thin:@172.16.9.81:1521:stdw </value> </parameter> <parameter> <name> password </name> <value> 111111 </value> </parameter> <parameter> <name> maxActive </name> <value> 100 </value> </parameter> <parameter> <name> maxWait </name> <value> 10000 </value> </parameter> <parameter> <name> driverClassName </name> <value> oracle.jdbc.driver.OracleDriver </value> </parameter> <parameter> <name> username </name> <value> soatest </value> </parameter> <parameter> <name> maxIdle </name> <value> 20 </value> </parameter> </ResourceParams> </GlobalNamingResources> <Service name= "Catalina "> <Connector acceptCount= "100 " connectionTimeout= "20000 " disableUploadTimeout= "true " port= "8099 " redirectPort= "8443 " maxSpareThreads= "75 " maxThreads= "150 " minSpareThreads= "25 "> </Connector> <Connector port= "8009 " protocol= "AJP/1.3 " protocolHandlerClassName= "org.apache.jk.server.JkCoyoteHandler " redirectPort= "8443 "> </Connector> <Engine defaultHost= "localhost " name= "Catalina "> <Host appBase= "webapps " name= "localhost "> <Logger className= "org.apache.catalina.logger.FileLogger " prefix= "localhost_log. " suffix= ".txt " timestamp= "true "/> </Host> <Logger className= "org.apache.catalina.logger.FileLogger " prefix= "catalina_log. " suffix= ".txt " timestamp= "true "/> <Realm className= "org.apache.catalina.realm.UserDatabaseRealm "/> </Engine> </Service> </Server> %TOMCAT_HOME%/conf/Catalina/localhost目录下的SOATEST.xml配置: <?xml version= '1.0 ' encoding= 'utf-8 '?> <Context docBase= "SOATEST " path= "/SOATEST " reloadable= "true " cookies= "true " crossContext= "true " privileged= "true " antiResourceLocking= "false " antiJARLocking= "false "> <ResourceLink name= "jdbc/testDB " global= "jdbc/testDB " type= "javax.sql.DataSource "/> </Context> 应用程序下的web.xml配置: <?xml version= "1.0 " encoding= "UTF-8 "?> <web-app version= "2.4 " xmlns= "http://java.sun.com/xml/ns/j2ee " xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance " xsi:schemaLocation= "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd "> <resource-ref> <description> DB Connection </description> <res-ref-name> jdbc/testDB </res-ref-name> <res-type> javax.sql.DataSource </res-type> <res-auth> Container </res-auth> </resource-ref> </web-app> jsp程序: <%@ page import= "javax.naming.Context "%> <%@ page import= "javax.sql.DataSource "%> <%@ page import= "javax.naming.InitialContext "%> <%@ page import= "java.sql.* "%> <%DataSource ds = null; try { Context initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup( "java:comp/env "); ds = (DataSource) envCtx.lookup( "jdbc/testDB "); if (ds != null) { out.println( "Connection is OK! "); Connection cn = ds.getConnection(); if (cn != null) { out.println( "cn is Ok! "); Statement stmt = cn.createStatement(); ResultSet rst = stmt.executeQuery( "select * from TEST_USER "); out.println( " <p> rst is Ok! " + rst.next()); while (rst.next()) { out.println( " <P> BOOK_CODE: " + rst.getString(2)); } cn.close(); } else { out.println( "rst Fail! "); } } else out.println( "Fail! "); } catch (Exception ne) { out.println(ne); } %> |