File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Problem with resultset or query? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Problem with resultset or query?" Watch "Problem with resultset or query?" New topic

Problem with resultset or query?

Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

I used the below code to find the number of entries in my database, but it fails to work... Please help me whats the problem here with my code..

: Code Edited :

Never try to be a hard-worker. Be a smart-worker.
My Blog
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1082

I do not think that you have provided actual code. Also It is bad practice to put jdbc code in JSPs

Could you please tell us following.

1.Where is connection in your code ? I guess db.connect() returns a connection

2.Where are you creating statement.

3. did you check log / console for output of System.out.println(e);

Use the following catch block, It will put stacktrace on jsp.

[ November 03, 2008: Message edited by: Shailesh Chandra ]

Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Here's the code which is throwing the exception:
First you set the variable ps to null. You don't have any code which assigns anything else to it, and then you try to call its executeQuery method. So you get a NullPointerException.

You shouldn't be putting this sort of code in a JSP. And you shouldn't be using a JSP as a test harness for the code either, because (as you can see) you don't get to see the exceptions properly. So stop doing that. Just write some plain old Java code to test your database accessing. Once you have it working, then put it back into a web application. (But preferably not into a JSP. Putting database code in a JSP hasn't been a best practice for several years now.)
I agree. Here's the link:
subject: Problem with resultset or query?
jQuery in Action, 3rd edition