当前位置: 技术问答>java相关
::::::::java连接数据库问题::::::::(召唤各位大虾ing)
来源: 互联网 发布时间:2015-03-27
本文导语: 程序运行后返回这样的信息: Error creating class: COM.ibm.db2.jdbc.app.DB2Driver Closing connections... 代码如下: package chinalife; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; class Adon extends Object { p...
程序运行后返回这样的信息:
Error creating class: COM.ibm.db2.jdbc.app.DB2Driver
Closing connections...
代码如下:
package chinalife;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
class Adon extends Object {
public static void main(String[] args) {
String driverName = "COM.ibm.db2.jdbc.app.DB2Driver";
String connectURL = "jdbc:db2:ebs";
Connection db = null;
try {
Class.forName(driverName);
db = DriverManager.getConnection(connectURL);
} catch (ClassNotFoundException e) {
System.out.println("Error creating class: " + e.getMessage());
} catch (SQLException e) {
System.out.println("Error creating connection: " + e.getMessage());
} finally {
System.out.println("Closing connections...");
try {
db.close();
} catch (SQLException e) {
System.out.println("Can't close connection.");
}
}
}
}
请问个为大虾,此错误怎么产生怎么解决
而且原来连接数据库使用如下代码可以正确连接:
IBMJdbcConn ibmjdbcconn = getPooledConnection(getDriver(), getURL(), getUserID(), password);
connBean = new DatabaseConnection(ibmjdbcconn.getJdbcConnection());
if(connBean == null)
{
return;
} else
{
......
哪种连接方式更好一些,且为什么,呵呵。
Error creating class: COM.ibm.db2.jdbc.app.DB2Driver
Closing connections...
代码如下:
package chinalife;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
class Adon extends Object {
public static void main(String[] args) {
String driverName = "COM.ibm.db2.jdbc.app.DB2Driver";
String connectURL = "jdbc:db2:ebs";
Connection db = null;
try {
Class.forName(driverName);
db = DriverManager.getConnection(connectURL);
} catch (ClassNotFoundException e) {
System.out.println("Error creating class: " + e.getMessage());
} catch (SQLException e) {
System.out.println("Error creating connection: " + e.getMessage());
} finally {
System.out.println("Closing connections...");
try {
db.close();
} catch (SQLException e) {
System.out.println("Can't close connection.");
}
}
}
}
请问个为大虾,此错误怎么产生怎么解决
而且原来连接数据库使用如下代码可以正确连接:
IBMJdbcConn ibmjdbcconn = getPooledConnection(getDriver(), getURL(), getUserID(), password);
connBean = new DatabaseConnection(ibmjdbcconn.getJdbcConnection());
if(connBean == null)
{
return;
} else
{
......
哪种连接方式更好一些,且为什么,呵呵。
|
捕捉的是ClassNotFoundException
COM.ibm.db2.jdbc.app.DB2Driver类没有找到
你该修改classpath路径了,把驱动包加进去
COM.ibm.db2.jdbc.app.DB2Driver类没有找到
你该修改classpath路径了,把驱动包加进去
|
Class.forName(driverName);这句出错了
db2的驱动程序没有找到!
db2的驱动程序没有找到!