File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC 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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Problem with resultset or query?" Watch "Problem with resultset or query?" New topic
Author

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: 1081

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.


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

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

Joined: Oct 14, 2005
Posts: 18166
    
    8

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: http://aspose.com/file-tools
 
subject: Problem with resultset or query?
 
Similar Threads
adding double values
Unable to Run Servlet from past two days
Image icon issue
Compress .zip using Java
Finding email attachment size using java mail api