permaculture playing cards*
The moose likes JDBC and the fly likes not able to establish connection for jdbcodbcdriver Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "not able to establish connection for jdbcodbcdriver" Watch "not able to establish connection for jdbcodbcdriver" New topic
Author

not able to establish connection for jdbcodbcdriver

Anshal Patel
Ranch Hand

Joined: Feb 07, 2010
Posts: 32
Hello everyone I am facing a problem when I try and connect my servlets to sql2000 database.

As a classic way Connection con is defined and Statement stmt is defined.

In the following code even after a series of sql queries and registering the drivers
both 'con' and 'stmt' are null till the end

At the end(before closing it) I modified if statement by printing error if con==null and it did get printed.

Please help me to understand the error

The code is as follows

Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2510
    
  10

Hi Ashal,

Please use code tags in your post.
You can edit your post by clicking on the Edit icon at its right top.


Regards, Jan


OCUP UML fundamental and ITIL foundation
youtube channel
Ravinderjit Singh
Ranch Hand

Joined: Jan 13, 2010
Posts: 78
Try with this code and make sure you have SQL Server driver jar file in classpath.

Anshal Patel
Ranch Hand

Joined: Feb 07, 2010
Posts: 32
do you mean sqljdbc.jar

the following is my classpath variable

C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar;C:\Microsoft SQL Server JDBC Driver 2.0\sqljdbc_2.0\enu\sqljdbc.jar


the problem is i get the exception ClassNotFoundException
when I register the drivers you wrote com....

Anshal Patel
Ranch Hand

Joined: Feb 07, 2010
Posts: 32
The connectivity issue is solved.I created a DSN for the same.

But now I have an error in the sql query.



It doesnt work

but this works


how do i put my parameters in the query
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2510
    
  10

(least preferable solution) You have to put your value within single quotes.
(most preferable solution) learn about PreparedStatement and parameter binding.

Regards, Jan
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2510
    
  10

There you go. I wasted my time on a duplicate post. You have already posted this here.
Anshal Patel
Ranch Hand

Joined: Feb 07, 2010
Posts: 32
issue resolved thanks to all
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: not able to establish connection for jdbcodbcdriver