db2java_java 连接 db2

classpath中有db2java,文件在dos黑屏下编译,执行可以完成,在eclipse上导入了db2java.zip。一直执行失败,如下Unabletoconnectionjava.sql.SQLException:Nosuitabledriveratjava.sq...

classpath中有db2java,文件在dos黑屏下编译,执行可以完成,

在eclipse上导入了db2java.zip。一直执行失败,如下

Unable to connection

java.sql.SQLException: No suitable driver

at java.sql.DriverManager.getConnection(Unknown Source)

at java.sql.DriverManager.getConnection(Unknown Source)

at ConnDB2.main(ConnDB2.java:32)

public static void main(String argv[]) {

Connection con = null;

Statement sta = null;

ResultSet res = null;

// String url ="jdbc:db2://localhost:50000/sample";

String url = "jdbc:db2:sample";

// String url ="jdbc:db2://127.0.0.1:50000/sample";

try {

Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");

con = DriverManager.getConnection(url, "db2admin", "db2admin");

sta = con.createStatement();

String query = " select * from Administrater.staff";

res = sta.executeQuery(query);

boolean Have = res.next();

if (!Have) {

System.out.print("No record\n");

System.exit(-1);

}

ResultSetMetaData rsmd = res.getMetaData();

for (int i = 1; i <= rsmd.getColumnCount(); i++) {

System.out.print(rsmd.getColumnName(i) + " ");

}

System.out.print("\n");

do {

for (int i = 1; i <= rsmd.getColumnCount(); i++) {

System.out.print(res.getString(i) + " ");

}

System.out.print("\n");

} while (res.next());

res.close();

sta.close();

con.close

} catch (ClassNotFoundException e) {

System.out.println("Failed to load JDBC/ODBC");

e.printStackTrace();

System.exit(0);

} catch (SQLException e) {

System.out.println("Unable to connection");

e.printStackTrace();

}catch(Exception e)

{

System.out.println("s");

}

}

那么在eclipse里面如何设置db2profile?

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值