aspose file tools*
The moose likes JDBC and the fly likes help regarding jdbc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "help regarding jdbc" Watch "help regarding jdbc" New topic
Author

help regarding jdbc

Anshal Patel
Ranch Hand

Joined: Feb 07, 2010
Posts: 32



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

Joined: Oct 13, 2005
Posts: 38840
    
  23
You will have a better chance of a helpful answer if we know what the thread is about.
Anshal Patel
Ranch Hand

Joined: Feb 07, 2010
Posts: 32
sorry sir i am new here I apologise for the wrong title.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38840
    
  23
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

Joined: Feb 07, 2010
Posts: 32
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30532
    
150

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.)


[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
parampreet sethi
Greenhorn

Joined: Aug 03, 2009
Posts: 27

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.


Param
Anshal Patel
Ranch Hand

Joined: Feb 07, 2010
Posts: 32
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

Joined: Feb 07, 2010
Posts: 32
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

Joined: Feb 07, 2010
Posts: 32
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30532
    
150

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help regarding jdbc