| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 784 人关注过本帖
标题:servlet:数据库连接池问题,Cannot create JDBC driver of class '' for co ...
只看楼主 加入收藏
wk1882625239
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-11-30
收藏
 问题点数:0 回复次数:0 
servlet:数据库连接池问题,Cannot create JDBC driver of class '' for connect URL 'null'
webdemo.xml(路径:C:\apache-tomcat-8.0.28\conf\Catalina\localhost)

<Context path="/webdemo" docBase="webdemo" debug="0">
<Resource name="jdbc/webdb" auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/webdb?characterEncoding=utf-8"
username="root"
password="020500"
maxActive="5"
maxIdle="2"
maxWait="3000"/>
</Context>

web.xml

<web-app>
<display-name>Project Name</display-name>
<servlet>
<servlet-name>ViewDictionary</servlet-name>
<servlet-class>chapter4.ViewDictionary</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>ViewDictionary</servlet-name>
<url-pattern>/servlet/ViewDictionary</url-pattern>
</servlet-mapping>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/webdb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>

doget方法
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html;charset=utf-8");
PrintWriter printWriter=response.getWriter();

try {
javax.naming.Context ctxContext=new javax.naming.InitialContext();
javax.sql.DataSource dsDataSource=(javax.sql.DataSource) ctxContext.lookup("java:/comp/env/jdbc/webdb");
Connection connection= dsDataSource.getConnection();
String sqlString="select * from t_dictionary";
PreparedStatement statement=connection.prepareStatement(sqlString);
ResultSet resultSet=statement.executeQuery();
StringBuilder stringBuilder=new StringBuilder();
stringBuilder.append("<table border='1'>");
stringBuilder.append("<tr><td>书名</td><td>价格</td></tr>");
while(resultSet.next()){
stringBuilder.append("<tr><td>"+resultSet.getString("english")+"</td><td>"+resultSet.getString("chinese")+"</td></tr>");
}
stringBuilder.append("</table>");
printWriter.print(stringBuilder.toString());
statement.close();
} catch (Exception e) {
e.printStackTrace();
}
}

求解,配置应该没错。
还有用DriverManager.getConnection(url, username, password);能连上
搜索更多相关主题的帖子: localhost 数据库连接 password create null 
2015-11-30 13:43
快速回复:servlet:数据库连接池问题,Cannot create JDBC driver of class '' f ...
数据加载中...
 
   



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

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