| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 539 人关注过本帖
标题:Tomcat连接池提示驱动错误
只看楼主 加入收藏
北方孤狼
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2008-5-10
结帖率:75%
收藏
已结贴  问题点数:10 回复次数:1 
Tomcat连接池提示驱动错误
tomcat中的server.xml
...
    <Resource name="jdbc/webdb2" auth="Container"
        type="javax.sql.DataSource"
        driverClassName="com.mysql.jdbc.Driver"
        url="jdbc:mysql://localhost:3306/webdb?characterEncoding=utf-8"
        username="root"
        password="sa123456"
        maxActive="200"
        maxIdle="50"
        maxWait="3000"
    />
...



tomcat中的webdemo3.xml
<Context path="/webdemo3" docBase="webdemo3" debug="0">
    <ResourceLink name="jdbc/webdb2" global="jdbc/webdb2" type="javax.sql.DataSource"/>
</Context>



项目里的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www. xmlns="http://xmlns. xsi:schemaLocation="http://xmlns. http://xmlns. id="WebApp_ID" version="3.1">
  <display-name>webdemo3</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>viewDictory</servlet-name>
    <servlet-class>webdemo3.chapter04.ViewDictionary</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>viewDictory</servlet-name>
    <url-pattern>/servlet/ViewDictionary</url-pattern>
  </servlet-mapping>
  <resource-ref>
    <description>DB Connection</description>
    <res-ref-name>jdbc/webdb2</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>
</web-app>



项目中的ViewDictionary.java
package webdemo3.chapter04;

import
import
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ViewDictionary
 */
public class ViewDictionary extends HttpServlet {
    private static final long serialVersionUID = 1L;
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ViewDictionary() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out=response.getWriter();
        try{
            javax.naming.Context ctx=new javax.naming.InitialContext();
            javax.sql.DataSource ds=(javax.sql.DataSource)ctx.lookup("java:/comp/env/jdbc/webdb2");
            Connection conn=ds.getConnection();
            
            
            PreparedStatement pstmt=conn.prepareStatement("select * from t_dictionary");
            
            ResultSet rs=pstmt.executeQuery();
            
            StringBuilder table=new StringBuilder();
            table.append("<table border='1'>");
            table.append("<tr><td>书名</td><td>价格</td></tr>");
            while(rs.next()){
                table.append("<tr><td>"+rs.getString("english")+"</td><td>"+rs.getString("chinese")+"</td></tr>");
            }
            table.append("</table>");
            out.println(table.toString());
            pstmt.close();
        }catch(Exception e){
            e.printStackTrace();
            out.println(e.getMessage());
        }
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

}



控制台错误信息:
java.sql.SQLException: Cannot create JDBC driver of class '' for connect URL 'null'
    at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2065)
    at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:1939)
    at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1412)
    at webdemo3.chapter04.ViewDictionary.doGet(ViewDictionary.java:37)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
    at org.apache.tomcat.(NioEndpoint.java:1521)
    at org.apache.tomcat.(NioEndpoint.java:1478)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:744)
Caused by: java.sql.SQLException: No suitable driver
    at java.sql.DriverManager.getDriver(DriverManager.java:315)
    at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2049)
    ... 26 more



jar包好用,在项目和tomcat都有



还有个问题一直没有解决,不知道和这个有没有关:
conn=DriverManager.getConnection("jdbc:mysql://localhost:3360/newsmanager","root","sa123456");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/newsmanager?user=root&password=sa123456");
第一个不好使 第二个好使 为什么
搜索更多相关主题的帖子: localhost password mysql 
2015-08-28 19:52
日知己所无
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:38
帖 子:427
专家分:2071
注 册:2014-3-22
收藏
得分:10 
>> Cannot create JDBC driver of class '' for connect URL 'null'
JDBC的jar包的环境没配好,上网查查具体配法儿吧

>> conn=DriverManager.getConnection("jdbc:mysql://localhost:3360/newsmanager","root","sa123456");
>> conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/newsmanager?user=root&password=sa123456");
第一个不好使的现象是什么样?确实挺奇怪的……
2015-08-30 17:48
快速回复:Tomcat连接池提示驱动错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019845 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved