servlet连接DB2报错java.lang.ClassNotFoundException: COM.ibm.db2.jdbc.net.DB2Driver

qdm2010 2004-04-14 11:07:16
servlet连接DB2报错java.lang.ClassNotFoundException: COM.ibm.db2.jdbc.net.DB2Driver
有哪位仁兄知道怎么回事吗?
...全文
1846 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ruisheng 2004-04-14
  • 打赏
  • 举报
回复
通过用ODBC连接吧,sun.jdbc.odbc.JdbcOdbcDriver
我试过几个连接方法只有这种可以连接成功
qdm2010 2004-04-14
  • 打赏
  • 举报
回复
有COM.ibm.db2.jdbc.net.DB2Driver这个包,
import java.io.*;
import java.sql.*;
import java.lang.*;
import javax.servlet.*;
import javax.servlet.http.*;
import COM.ibm.db2.jdbc.net.DB2Driver;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/

public class conn
extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
}

//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
con(request, response);
}

//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
con(request, response);
}

public void con(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>test</title></head>");
out.println("<body bgcolor=\"#ffffff\">");


String sDBDriver = "COM.ibm.db2.jdbc.app.DB2Driver";
String sConnDataBase = "jdbc:db2://192.168.2.27/SAMPLE";
String sConnUser = "db2admin";
String sConnPassd = "password";
Connection con = null;

DatabaseMetaData datameta;
Statement stmt;
ResultSet rs;
out.println("ok1?");
try {
Class.forName(sDBDriver).newInstance();

out.println("ok0");
con = DriverManager.getConnection(sConnDataBase, sConnUser, sConnPassd);
out.println("ok2");
stmt = con.createStatement();
out.println("ok?");
stmt.close();
con.close();

}
catch (Exception e) {
e.printStackTrace();
}

out.println("<p>The servlet has received a GET. This is the reply.</p>");
out.println("</body></html>");

}

//Clean up resources
public void destroy() {
}
}
可以编译通过
jasonme 2004-04-14
  • 打赏
  • 举报
回复
十有八九是数据库驱动的问题。

检查一下驱动
flyforlove 2004-04-14
  • 打赏
  • 举报
回复
COM.ibm.db2.jdbc.net.DB2Driver
你有包含这个class得包么?
qdm2010 2004-04-14
  • 打赏
  • 举报
回复
还是不行啊,我的db2版本是8,用的是JBuilder9
CoolAbu 2004-04-14
  • 打赏
  • 举报
回复
String sDBDriver = "COM.ibm.db2.jdbc.app.DB2Driver";
-------------------------------------^^^换成net试试

DB2的版本和JDBC驱动的不同,连接字符串有一定区别的。

如果是驱动是db2jcc.jar.
用com.ibm.db2.jcc.DB2Driver连接


还有你把JDBC驱动Copy到WEB-INF\lib文件夹下。

81,122

社区成员

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

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