File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Getting a problem while using database connectivity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Getting a problem while using database connectivity" Watch "Getting a problem while using database connectivity" New topic

Getting a problem while using database connectivity

sushil parti

Joined: Jun 21, 2009
Posts: 3

i am a newbie to java... i have just joined an institute for that and the tutor is teaching java on netbeans
but i liked eclipse more. So i am doing on that.
A few days ago my tutor taught us database connectivity without using DSN so that it could be deployed easily which i have implemented in the code below
But i am getting an error :

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

I have checked the code again and again but can't find the error in it. Further my teacher is not able to find the error and is blaming the eclipse for that and is saying it is due to some internal error of laptop. I am not sure what to do ..

please help me a soon as is the code.. :

Please reply if any one here knows the solution......
Thank you
Jan Cumps

Joined: Dec 20, 2006
Posts: 2565

Welcome to JavaRanch, sushil.

Please read these instructions on how to use code tags to make your post more readable.
We have a general tutorial on how to ask questions.

Regards, Jan

OCUP UML fundamental and ITIL foundation
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423

try to change this line:

and use an absolute pathname instead of relative, for example:

sushil parti

Joined: Jun 21, 2009
Posts: 3
Hi Ireneusz
Thanks for replying....

i changed that relative address to have an absolute one .
But still it is not working properly..

Actually There is no compilation error. But when i click on login button after putting the username and password
the error comes.

any guesses what should i do
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

The code you have is a little odd. This line:

is a funny way of registering a driver, and kind of works against one of the principals of JDBC: that you code should be portable.

The error you see usually occurs when you are using a DSN rather than a trying a DSN-less connection. The error means that ODBC can't find a data source name. Given you have been working with DSN version previously, I would check the code you are actually running. Are there any old classes kicking about?

I'm not sure what the "DriverID=22;READONLY=false" in your connection string means - I've only ever seen it used (mis)using JDBC to connect to Excel. Try removing
it from the string.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
sushil parti

Joined: Jun 21, 2009
Posts: 3
thanks everybody for your help
well somehow my code is running again after i replaced it with following code
but i still can't get how. Does any body know??
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

I can't easily tell what is different between the new and old code because the old code is long and unformatted.

I do want to point out that your application is vulnerable to SQL Injection where someone can enter SQL in the user/password fields and login even without a valid id. You really should be using a PreparedStatement.

[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
I agree. Here's the link:
subject: Getting a problem while using database connectivity
It's not a secret anymore!