Tomcat连接池出错:java.sql.SQLException: Cannot load JDBC driver class 'null'---

JCJC错别字检测-田春峰
博客专家认证
2003-03-26 01:42:44
可以成功初始化Context,但是getConnection出错

java.sql.SQLException: Cannot load JDBC driver class 'null'

我的代码如下:

package SunShineSCM;

import javax.naming.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import javax.sql.*;
import java.sql.*;

public class Users{
String foo = "Not Connected";
int bar = -1;
public void init() {
foo += " 1";
try{
foo += " 2";
Context initCtx = new InitialContext();
Context ctx = (Context) initCtx.lookup("java:comp/env");
foo += " 3-----------------";
if(ctx == null )
{
foo += " 4------------ ";
throw new Exception(" the Context initialize is failure Boom - No Context");
}
// ds = (DataSource)envCtx.lookup("jdbc/EmployeeDB");
// con = ds.getConnection();
// DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/JNDISunShineSCM");
DataSource ds = (DataSource)ctx.lookup("jdbc/JNDISunShineSCM");

foo += " Begin Get DataSource ";
if (ds != null) {
foo = " the Context initialize is success ";
foo = "Begin get connection ";
Connection conn = ds.getConnection();
foo = "End get connection";
if(conn != null) {
foo = "Got Connection "+conn.toString();
Statement stmt = conn.createStatement();
ResultSet rst = stmt.executeQuery( "select * from users");
if(rst.next()) {
foo=rst.getString(1);
bar=rst.getInt(2);
}
conn.close();
foo =" Get DataSource Sucessed ";
}
}
}catch(Exception e) {
foo += " catch -----------------error = "+ e.toString() +"-----" + e.getMessage() ;
e.printStackTrace();
}
}
public String getFoo() { return foo; }
public int getBar() { return bar;}
}
请大家帮忙
...全文
156 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Kidy 2003-04-30
  • 打赏
  • 举报
回复
我也遇到这个情况,也把驱动放到tomcat/common/lib下了,怎么办啊?请救命。
rabbitx 2003-03-26
  • 打赏
  • 举报
回复
是不是没有把驱动放到/lib目录下?
javanew 2003-03-26
  • 打赏
  • 举报
回复
up

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧