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 PreparedStatement error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "PreparedStatement error" Watch "PreparedStatement error" New topic
Author

PreparedStatement error

Tiago Hillebrandt
Greenhorn

Joined: Jun 07, 2008
Posts: 19
I have created a method to verifies the number of lines from a mysql database table, but is happens this error:

description The server encountered an internal error () that prevented it from fulfilling this request.

exception org.apache.jasper.JasperException: java.lang.NullPointerException


Debugging, on try sets the prepareStatement to pst variable the error happens.

What is the error? The table havens 3 registers!

Sorry for english!


[ June 07, 2008: Message edited by: Tiago Hillebrandt ]
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081


this.pst = this.con.prepareStatement("SELECT count(*) AS count FROM ?;");


1. Do not set table name as bind variable.

2. you need not to add semi colon in query.


Thanks,
Shailesh


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

Joined: Oct 14, 2005
Posts: 18541
    
    8

And as for the NullPointerException, that means that the variable "con" is null. Perhaps your mysql.connect() tries to set it to something but fails to do so.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: PreparedStatement error
 
Similar Threads
Sorting Of Array From Even Number To Odd Number
Inheritance problem
Abstract Class doubt
Writing arrays
Clean database