aspose file tools*
The moose likes JDBC 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
Bookmark "Getting a problem while using database connectivity" Watch "Getting a problem while using database connectivity" New topic
Author

Getting a problem while using database connectivity

sushil parti
Greenhorn

Joined: Jun 21, 2009
Posts: 3

Hi,
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 possible..here is the code.. :



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

Joined: Dec 20, 2006
Posts: 2495
    
    8

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
youtube channel
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
Hi,

try to change this line:

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


sushil parti
Greenhorn

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
Bartender

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
Greenhorn

Joined: Jun 21, 2009
Posts: 3
Hi
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30294
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Getting a problem while using database connectivity