aspose file tools
The moose likes JDBC and Relational Databases and the fly likes NullPointer exception on prepared Insert Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "NullPointer exception on prepared Insert" Watch "NullPointer exception on prepared Insert" New topic

NullPointer exception on prepared Insert

Vivienne Lambe

Joined: Oct 01, 2004
Posts: 4
Hope someone can help. I have been working on this for hours and cant find the problem. I have an Insert statement, but when I try to actually prepare it, I receive a null pointer exception.
I would appreciate any help with this, i have tried everything.

try {
PreparedStatement pstmt = null;
StringBuffer sbSqlUpdateServer = new StringBuffer("INSERT INTO EventLog (EVENT_DATE, EVENT_URL, DOWNLOAD_SIZE) VALUES (?,?,?)");
pstmt = connection.prepareStatement(sbSqlUpdateServer.toString());

Exception in thread "main" java.lang.NullPointerException
at com.quickplay.parser.CreateEventLogEntries.insertEventRow(Compiled Code)
at com.quickplay.parser.CreateEventLogEntries.getTokens(Compiled Code)
at com.quickplay.parser.CreateEventLogEntries.readLogFile(Compiled Code)
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

I'm assuming your connection is not null?
Vivienne Lambe

Joined: Oct 01, 2004
Posts: 4
I verified the Connection is valid.
I think the problem is with the date field. I have tried using to_date(?, 'dd/mm/yyyy') but still the same. Column defined as "Date" in table so i'm not sure if it needs a specific type when inserting.
Thanks for your reply.
Vivienne Lambe

Joined: Oct 01, 2004
Posts: 4
Found problem, unstable connection
Mike Rainville
Ranch Hand

Joined: May 29, 2004
Posts: 36
See if this helps ...

PreparedStatement pstmt = null; // moved before try block

try {
/* PreparedStatement pstmt = null; moved */
It is sorta covered in the JavaRanch Style Guide.
subject: NullPointer exception on prepared Insert