Hi,
I want to write a program to connect DB2 by jdbc, and i do not want to
provide user name and passwords?
in IBM site, i find a sample:
http://publib.boulder.ibm.com/infoce...c/c0023797.htm
and i wrote a similar one:
public static void main(String[] args) {
try {
String dbdriver = "com.ibm.db2.jcc.DB2Driver"; //get db driver
Class.forName(dbdriver);
String url = "jdbc:db2://CNDT50058324GV:50000/SBO_DB";
String dbUserName = "admin";// user name of the windows user account name
String dbPassword = "dev";// password of the windows user password
Connection conn = DriverManager.getConnection(url);
String sql = "SELECT Key From Test";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
conn.commit();
while(rs.next()){
System.out.print("col:\t");
System.out.println(rs.getString(1));
}
conn.close();
System.out.println("connected successfully");
} catch (ClassNotFoundException ex) {
System.out.println(
"ConnectionFactory.getConnection() exception: JDBC driver not defined.");
} catch (SQLException ex) {
System.out.println( "DriverManager.getConnection() exception"
+ ex);
}
unfortunately, it failed with an exception: "null userid not supported",
but why the sample of IBM works, yet mine fails?
anybody can help me? thanks
--
Best regards
Liang Zhang
Developer
SAP Labs China
T: +86 21 61006699-7775
F: +86 21 50807498
Email li*********@sap.com
SAP LABS CHINA : INNOVATE THE FUTURE