Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to insert timestamp into derby databse

 
John Smith
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to update a derby timestamp field with a java.sql.timestamp, but am getting this error when doing so

SQLException e = java.sql.SQLSyntaxErrorException: Syntax error: Encountered "00" at line 1, column 43.
java.sql.SQLSyntaxErrorException: Syntax error: Encountered "00" at line 1, column 43.
at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at org.apache.derby.client.am.Statement.executeUpdate(Unknown Source)
at DBServer.conversation.run(conversation.java:263)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.apache.derby.client.am.SqlException: Syntax error: Encountered "00" at line 1, column 43.
at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source)
at org.apache.derby.client.am.Statement.completeExecuteImmediate(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.parseEXCSQLIMMreply(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.readExecuteImmediate(Unknown Source)
at org.apache.derby.client.net.StatementReply.readExecuteImmediate(Unknown Source)
at org.apache.derby.client.net.NetStatement.readExecuteImmediate_(Unknown Source)
at org.apache.derby.client.am.Statement.readExecuteImmediate(Unknown Source)
at org.apache.derby.client.am.Statement.flowExecute(Unknown Source)
at org.apache.derby.client.am.Statement.executeUpdateX(Unknown Source)
... 3 more

I know the reason is due to the format of my timestamp being
0000-00-00 00:00:00

When it hits the 00:.. is when the error is thrown.


Here is the code I'm attempting to run

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brandon,
You really should use a PreparedStatement rather than fiddling with date formats. This makes your query safer and more portable.

The query would then look like:
"UPDATE PATRONS SET LOGINTIME = ? and NUM_LOGINS = ? where PATRONID = ?"

And you would pass the three parameters via stmt.setXXX(). There is a setDate() that will take a Java date value so you won't have this problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic