Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with resultset or query?

 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 :
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic