This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes PreparedStatement error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "PreparedStatement error" Watch "PreparedStatement error" New topic

PreparedStatement error

Tiago Hillebrandt

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

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.


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

Joined: Oct 14, 2005
Posts: 19728

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.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: PreparedStatement error
It's not a secret anymore!