473,405 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

can I connect to DB2 using windows authentication?

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
1 6265
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Brian Pittman | last post by:
Hi all, As the subject says I'm having trouble connecting to SQL Server 2K via Visual Studio.NET 2002 (VB). It tells me that SQL Server does not exist or access is denied. I know that the...
7
by: Reza | last post by:
Hello The project was working, where I had a domain user registered in the database as a user, and I used that user to connect the datebase. Everything was fine and it was working, then when I...
3
by: Reza | last post by:
Hello I tried this friday, but didn't get anywhere so trying again Basically, I have a fixed list of people that can access the application in the Intranet, and with the policy of the company the...
7
by: Oenone | last post by:
Sorry for the cross-post but I've really no idea where this is best suited. I've an ADO.NET application which connects to a SQL Server database. I have spent the entire morning trying to get it...
5
by: toupeira23 | last post by:
Hello I'm trying to connect to another server via WMI, and it works just fine. But everytime it first tries to connect with the current user credentials, which naturally don't exist on the...
4
by: traceable1 | last post by:
I have a couple new servers - Windows 2003 R2 - with SQL Server 2000 SP4 installed. They are all Active/Active clustered instances (my first ones). I am trying to create database links to other...
0
by: jordo | last post by:
I have an asp.Net app that connects to the WSS 2.0 list web service. I'm having issues with IIS and .Net configurations and hope that someone can help me. My ideal configuration is: asp.net:...
1
by: Ben Hanson | last post by:
I've scoured Google searching for an answer that seems like it should be easy but apparently isn't...when I open SSMS to connect to a SQL 2005 database and choose Windows authentication, it greys...
3
by: =?Utf-8?B?Ulc=?= | last post by:
Using this code: Dim oConn As SqlClient.SqlConnection oConn = New SqlClient.SqlConnection() oConn.ConnectionString = "..." 'Connection string I got via an .udl file oConn.Open() I get an...
3
by: =?Utf-8?B?ZGF2aWQ=?= | last post by:
Last week I asked a question about connection to database from client machine (developer machine). I have changed the database security setup for "SQL Server and Windows" under (local)Windows NT...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.