Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help regarding jdbc

 
Anshal Patel
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



I have the above servlet which consists of three methods dopost doget and lookupinfo.
Lookup info contains the code to connect the database named MEDICAL and retrieve corressponding data.The data base I am using is sql 2000

But the problem is i do not get anything in the 'msg' string also i tried printing when con==null and stmt==null then those statements got executed(it was ofcourse by commenting the close commands)

A quick reply would be really helpful.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50225
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have a better chance of a helpful answer if we know what the thread is about.
 
Anshal Patel
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry sir i am new here I apologise for the wrong title.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50225
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apology accepted; since you are new (welcome ), I have edited your post with the code button, and you can see how much better it looks. You can correct the title by clicking the EDIT button on your post and changing the subject at the top of the window. On this forum (JDBC), please click the "disable smilies" box.

What happens when you try the same code in a standalone class, using the same driver and printing out the result set?
 
Anshal Patel
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried it with a simple html file
and it doesnt work there either.I have attached the file if you need it
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ansal,
What does "doesn't work" mean? Did it throw an exception? What did it say?

One thing I see that is a problem is the following line of code. There should be quotes around the string you are comparing d_name too. (It would also be better to use a PreparedStatement to prevent SQL Injection attacks while we are discussing that line.)
 
parampreet sethi
Greenhorn
Posts: 27
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One simple way to debug the issue is, see the below mentioned code:



Now try executing the query as printed on console into your DB Client. This will ensure that there is no problem with the query. If it works, you can revert back to original code.

As Jeanne pointed, Its better to use PreparedStatement instead of Statement because of security reasons and also PreparedStatement is compiled once at server and later being replaced by Bind variables.
 
Anshal Patel
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is the code correct? I mean where do I have to store my medical database coz I think the database is not getting connected leave the queries apart as 'con' is null till the end.
 
Anshal Patel
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for showin me a new method for sql.i will try it and by 'doesnt work ' i mean that i modified the last two 'if' statements by printing something if they were null and they both got printed so in short when the finally code is executed 'con' is null
 
Anshal Patel
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I request the admin to delete this thread as I have posted a new topic with a new title considering that I made a mistake.

Please delete this thread
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anshal Patel wrote:I request the admin to delete this thread as I have posted a new topic with a new title considering that I made a mistake.

Please delete this thread

We prefer not to delete things as others with the same problem can benefit from seeing the solution.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic