aspose file tools*
The moose likes JDBC 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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "NullPointer exception on prepared Insert" Watch "NullPointer exception on prepared Insert" New topic
Author

NullPointer exception on prepared Insert

Vivienne Lambe
Greenhorn

Joined: Oct 01, 2004
Posts: 4
Hi
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
Rancher

Joined: Mar 06, 2001
Posts: 13459

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

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
Greenhorn

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 */
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NullPointer exception on prepared Insert