Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

not able to establish connection for jdbcodbcdriver

 
Anshal Patel
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2586
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ravinderjit Singh
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try with this code and make sure you have SQL Server driver jar file in classpath.

 
Anshal Patel
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2586
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(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
Posts: 2586
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There you go. I wasted my time on a duplicate post. You have already posted this here.
 
Anshal Patel
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
issue resolved thanks to all
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic