ibm.data.db2的类型初始值设定项引发异常 40
连接字符串是这样写的:stringsql="server=10.0.0.1:50000;database=XXX;uid=xxx;pwd=xxx";DB2Connecti...
连接字符串是这样写的:string sql = "server=10.0.0.1:50000;database=XXX;uid=xxx;pwd=xxx";
DB2Connection conn = new Db2connection(sql);
然后就报错了。麻烦帮我看看吧 谢谢 展开
DB2Connection conn = new Db2connection(sql);
然后就报错了。麻烦帮我看看吧 谢谢 展开
3个回答
展开全部
给你一个实际通过的例子吧,希望能帮到您。
public class DB2JDBCtest {
private Connection conn;
//url有两种写法,分别使用予远程访问和本地访问,但远端访问方式比较普遍,如相访问本机,IP写localhost即可
private String url = "jdbc:db2://localhost:50000/XXX";//XXX为数据库名
private String classforname = "COM.ibm.db2.jdbc.net.DB2Driver";
//本地访问url写法
// private String url = "jdbc:db2:GP";
// private String classforname = "COM.ibm.db2.jdbc.app.DB2Driver";
//用户名和密码,随个人的设置而不同
private String uid = "administrator";
private String pwd = "XXX";
//声明三个预编译语句,分别用来查找,删除,添加
static PreparedStatement pStmt1, pStmt2, pStmt3;
public DB2JDBCtest(){}
/**
* <p>通过DB2 JDBC驱动获得数据库连接</p>
* @return Connection
*/
public Connection getConnection()
{
try
{
Class.forName(classforname);
if (conn == null || conn.isClosed())
conn = DriverManager.getConnection( url, uid, pwd);
}
catch (ClassNotFoundException ex)
{
ex.printStackTrace();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return conn;
}
public class DB2JDBCtest {
private Connection conn;
//url有两种写法,分别使用予远程访问和本地访问,但远端访问方式比较普遍,如相访问本机,IP写localhost即可
private String url = "jdbc:db2://localhost:50000/XXX";//XXX为数据库名
private String classforname = "COM.ibm.db2.jdbc.net.DB2Driver";
//本地访问url写法
// private String url = "jdbc:db2:GP";
// private String classforname = "COM.ibm.db2.jdbc.app.DB2Driver";
//用户名和密码,随个人的设置而不同
private String uid = "administrator";
private String pwd = "XXX";
//声明三个预编译语句,分别用来查找,删除,添加
static PreparedStatement pStmt1, pStmt2, pStmt3;
public DB2JDBCtest(){}
/**
* <p>通过DB2 JDBC驱动获得数据库连接</p>
* @return Connection
*/
public Connection getConnection()
{
try
{
Class.forName(classforname);
if (conn == null || conn.isClosed())
conn = DriverManager.getConnection( url, uid, pwd);
}
catch (ClassNotFoundException ex)
{
ex.printStackTrace();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return conn;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询