This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes SQL Server DSN - JdbcOdbcDriver Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "SQL Server DSN - JdbcOdbcDriver" Watch "SQL Server DSN - JdbcOdbcDriver" New topic

SQL Server DSN - JdbcOdbcDriver

Stephen Boston
Ranch Hand

Joined: Jul 14, 2005
Posts: 165
Hi guys! I'm hoping you can steer me in the right direction on this. Here is a snip of the code I'm using to connect to a MS SQL database.

This works just fine. But I've set the UserID and Password in my class. What I want to do is let the DSN I've setup on my PC to use the userID and password that is established in it.

So I modify my code like this.


Compile and run the application and I get a SQl Exception - Login failed for user '<null>'

Am I missing something here or is the JdbcOdbcDriver not up to this?

Thanks for any help you can offer.


Steve<br /> <br />No matter where you go, there you are.<br /> <br />"My evil self is at the door, and I have no power to stop it."
Stephen Boston
Ranch Hand

Joined: Jul 14, 2005
Posts: 165
Well, all my research hasn't turned up anything to help, so I've altered my class to accept DSN, UserID and Password as arguments. I've set up a login form to call the method in the class and bounce a simple query against the database and catch and handle any exception that may come back that deals with the user id or password.

Does anyone have a better way to approach this?

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33132

I haven't used SQL Server so I'm not sure. In general, it is good to put the username/password in a property file. That way it isn't hardcoded into the app. Not as good as what you are trying to do, but better than nothing.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Stephen Boston
Ranch Hand

Joined: Jul 14, 2005
Posts: 165

Thank you for your reply. I hadn't thought of a property file (maybe that is because I haven't discovered those yet. )

I will investigate that and see if that will work better than the login form method. If it don't work for this application, it will come in handy for another application I'm working up for dog agility club (Contact Zonies in Phoenix Arizona http:/// in case someone is wondering. )

[ August 20, 2005: Message edited by: Stephen Boston ]
I agree. Here's the link:
subject: SQL Server DSN - JdbcOdbcDriver
It's not a secret anymore!