首先我把db2java.zip和db2jcc.jar都加到了类路径中,代码如下:但连接却报错。
Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
String url="jdbc:db2://127.0.0.1:5000/check";
//sample为你的数据库名
String user="sb";
String password="111";
Connection conn= DriverManager.getConnection(url,user,password);
PreparedStatement ps=conn.prepareStatement("select * from administrator.user_info");
ResultSet rs=ps.executeQuery();
while (rs.next()){
System.out.println("user_no="+rs.getString("user_no")+
"user_name="+rs.getString("user_name"));
} conn.close();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}用这个驱动名的时候报错:com.ibm.db2.jcc.c.DisconnectException: [ibm][db2][jcc][t4][2043][11550] 异常 java.net.ConnectException:打开端口 5,555 上服务器 /127.0.0.1 的套接字时出错,消息为:Connection refused: connect。如果驱动类换成:COM.ibm.db2.jdbc.app.DB2Driver,则报标题的错。我怀疑监听端口不是5000,因为我运行netstat -an,查看不到5000端口。请问这是怎么回事?db2版本是9.1企业版
Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
String url="jdbc:db2://127.0.0.1:5000/check";
//sample为你的数据库名
String user="sb";
String password="111";
Connection conn= DriverManager.getConnection(url,user,password);
PreparedStatement ps=conn.prepareStatement("select * from administrator.user_info");
ResultSet rs=ps.executeQuery();
while (rs.next()){
System.out.println("user_no="+rs.getString("user_no")+
"user_name="+rs.getString("user_name"));
} conn.close();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}用这个驱动名的时候报错:com.ibm.db2.jcc.c.DisconnectException: [ibm][db2][jcc][t4][2043][11550] 异常 java.net.ConnectException:打开端口 5,555 上服务器 /127.0.0.1 的套接字时出错,消息为:Connection refused: connect。如果驱动类换成:COM.ibm.db2.jdbc.app.DB2Driver,则报标题的错。我怀疑监听端口不是5000,因为我运行netstat -an,查看不到5000端口。请问这是怎么回事?db2版本是9.1企业版
第二个:没发现有用大写做包名称的。
这里面的驱动类都是不一样的,9.1的zip驱动里面,包名的确是大写的com,你解压看看就知道了。
怎么出来webserivces了?