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
有哪位仁兄知道怎么回事吗?
...全文
1002 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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文件夹下。
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告