浏览 7366 次
锁定老帖子 主题:『提问』Tomcat5 数据源配置错误
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (1)
|
|
---|---|
作者 | 正文 |
发表时间:2004-08-09
Tomcat5 mysql4 配置文件: <DefaultContext reloadable="true"/> <Context path="/RM" docBase="RM" debug="5" reloadable="true" crossContext="true"> <Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_DBTest_log." suffix=".txt" timestamp="true"/> <Resource name="RMDB" auth="Container" type="javax.sql.DataSource"/> <ResourceParams name="RMDB"> <parameter> <name>factory</name> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value> </parameter> <!-- Maximum number of dB connections in pool. Make sure you configure your mysqld max_connections large enough to handle all of your db connections. Set to 0 for no limit. --> <parameter> <name>maxActive</name> <value>100</value> </parameter> <!-- Maximum number of idle dB connections to retain in pool. Set to 0 for no limit. --> <parameter> <name>maxIdle</name> <value>30</value> </parameter> <!-- Maximum time to wait for a dB connection to become available in ms, in this example 10 seconds. An Exception is thrown if this timeout is exceeded. Set to -1 to wait indefinitely. --> <parameter> <name>maxWait</name> <value>10000</value> </parameter> <!-- MySQL dB username and password for dB connections --> <parameter> <name>username</name> <value>root</value> </parameter> <parameter> <name>password</name> <value></value> </parameter> <!-- Class name for the old mm.mysql JDBC driver - uncomment this entry and comment next if you want to use this driver - we recommend using Connector/J though <parameter> <name>driverClassName</name> <value>org.gjt.mm.mysql.Driver</value> </parameter> --> <!-- Class name for the official MySQL Connector/J driver --> <parameter> <name>driverClassName</name> <value>com.mysql.jdbc.Driver</value> </parameter> <!-- The JDBC connection url for connecting to your MySQL dB. The autoReconnect=true argument to the url makes sure that the mm.mysql JDBC Driver will automatically reconnect if mysqld closed the connection. mysqld by default closes idle connections after 8 hours. --> <parameter> <name>url</name> <value><![CDATA[url=jdbc:mysql://localhost:3306/rmdb?useUnicode=true&characterEncoding=GB2312]]></value> </parameter> </ResourceParams> </Context> 错误提示信息: org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'com.mysql.jdbc.Driver' for connect URL 'url=jdbc:mysql://localhost:3306/rmdb?useUnicode=true&characterEncoding=GB2312' at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:780) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540) at com.rm.servlet.TestDataSource.doGet(TestDataSource.java:85) at javax.servlet.http.HttpServlet.service(HttpServlet.java:689) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683) at java.lang.Thread.run(Thread.java:534) Caused by: java.sql.SQLException: No suitable driver at java.sql.DriverManager.getDriver(DriverManager.java:243) at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:773) ... 28 more 你的分析: 注意:java.sql.SQLException: No suitable driver 我在网上搜了下,好像没有人遇到类似的错误。 我查了下Tomcat5的文档,说是支持jdbc2.0,就把原来的mysqlconnector3 .0换作mysqlconnector2.0的,可是问题依旧。 我已经将jdbc的驱动程序的包放到common/lib下面。 server.xml的配置如上面。 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2004-08-09
补充一下:
我使用如下代码可以进行连接: Class.forName("com.mysql.jdbc.Driver");.newInstance();; conn =DriverManager.getConnection("jdbc:mysql://localhost:3306/rmdb?user=root&password=&useUnicode=true&characterEncoding=GB2312");; |
|
返回顶楼 | |
发表时间:2004-08-09
根据我的体会:
mysql4.0.x以下版本用mysqlconnector3.0.x版本 mysql4.1.x版本用mysqlconnector3.1.x版本 我的jdbc3.0.8是怎么也连不上我的mysql4.1.1alpha,换成jdbc3.1.11alpha马上就好用了。 不知道对你是否有用,good luck |
|
返回顶楼 | |
发表时间:2004-08-09
>From David:
Here's first what should be in {TOMCAT_HOME}/conf/Catalina/localhost/DBTest.xml: <Context path="/DBTest" docBase="DBTest" debug="0" privileged="false"> <!-- Loggers, valves, other stuff here --> <Resource name="jdbc/DbTest" auth="container" type="javax.sql.DataSource"/> <ResourceParams name="jdbc/DbTest"> <parameter> <name>factory</name> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value> </parameter> <parameter> <name>maxActive</name> <value>100</value> </parameter> <parameter> <name>maxIdle</name> <value>30</value> </parameter> <parameter> <name>maxWait</name> <value>100000</value> </parameter> <!-- Customize with your database username --> <parameter> <name>username</name> <value>DBTestUser</value> </parameter> <!-- Customize with your database password here --> <parameter> <name>password</name> <value>*********</value> <parameter> <name>driverClassName</name> <value>com.mysql.jdbc.Driver</value> </parameter> <!-- Customize with your mysql url --> <parameter> <name>url</name> <value>jdbc:mysql://localhost:3306/DBTest?autoReconnect=true</value> </parameter> </ResourceParams> </Context> ----------------------------------------------------- Ok, now what should be in {TOMCAT_HOME}/webapps/DBTest/WEB-INF/web.xml: <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd";> <web-app> <display-name>DbTest Application</display-name> <!-- All your servlet definitions, mappings, welcome file specs, taglibs, etc, ... are placed here. --> <!--+ resource-ref here to make the database pool available in this application +--> <resource-ref> <description>DBTest Database</description> <res-ref-name>jdbc/DbTest</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> </web-app> --------------------------------------------------------- This exact formula has worked for me in I can't even count how many apps I've setup. --David |
|
返回顶楼 | |
发表时间:2004-08-09
<Context path="/RMMS" docBase="RMMS"
debug="0" privileged="false"> <!-- Loggers, valves, other stuff here --> <Resource name="RMDB" auth="container" type="javax.sql.DataSource"/> <ResourceParams name="RMDB"> <parameter> <name>factory</name> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value> </parameter> <parameter> <name>maxActive</name> <value>100</value> </parameter> <parameter> <name>maxIdle</name> <value>30</value> </parameter> <parameter> <name>maxWait</name> <value>100000</value> </parameter> <!-- Customize with your database username --> <parameter> <name>username</name> <value>root</value> </parameter> <!-- Customize with your database password here --> <parameter> <name>password</name> <value></value> </parameter> <parameter> <name>driverClassName</name> <value>com.mysql.jdbc.Driver</value> </parameter> <!-- Customize with your mysql url --> <parameter> <name>url</name> <value>jdbc:mysql://localhost:3306/rmdb?useUnicode=true&characterEncoding=GB2312</value> </parameter> <parameter> <name>removeAbandoned</name> <value>true</value> </parameter> <parameter> <name>removeAbandonedTimeout</name> <value>60</value> </parameter> </ResourceParams> </Context> ----------------- 我的配置文件内容。 |
|
返回顶楼 | |