Forums Register Login

how to insert timestamp into derby databse

+Pie Number of slices to send: Send
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

+Pie Number of slices to send: Send
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.
Onion rings are vegetable donuts. Taste this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 10660 times.
Similar Threads
Statement stmt SQL syntax error
import data from large csv file. Help.
Issue with Date insertion
Apache Derby Sql
sql date
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 15:50:57.