By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,236 Members | 1,449 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,236 IT Pros & Developers. It's quick & easy.

can I connect to DB2 using windows authentication?

P: n/a
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

Aug 25 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Liang,

You must change connection url.

If you want to connect from a Java program without supplying password
you must use implicit connection. Implicit connections are connections,
that use local protocol. In your program you specified hostname and
connection port. This means tcpip and type-4 driver -- in that case
you always have to provide password. Specify only database name
(catalogued on your system as local db), which will use type-2 driver
and local, implicit connection.

-- Artur Wronski

Aug 26 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.