• Post Reply Bookmark Topic Watch Topic
  • New Topic

chapter 10 OCPJP Study guide Sybex: incorrect format for TIMESTAMP  RSS feed

 
Piet Souris
Rancher
Posts: 1943
66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

I'm working on chapter 10 from the Sybex OCPJP study guide, and I ran the code given on page 509:

However, I keep getting this error:

java.sql.SQLDataException: The syntax of the string representation of a date/time value is incorrect.
at org.apache.derby.client.am.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at org.apache.derby.client.am.ClientStatement.executeUpdate(Unknown Source)
at chapter10.justcodes.SetupDerbyDatabase.main(SetupDerbyDatabase.java:37)
Caused by: ERROR 22007: The syntax of the string representation of a date/time value is incorrect.

Now, I have no idea what is wrong in my code. Someone who sees what I'm doing wrong?
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 4088
33
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The format is hh:mm:ss[.nnnnnn] so try changing 2001-05-06 02:15 to 2001-05-06 00:02:15
 
Piet Souris
Rancher
Posts: 1943
66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul, that worked!

But I am still baffled:

1) my code is from the book of Jeanne and Scott and so far I have not seen any remarks from people for which this also does not work (am I really the first?)
2) if you look at the official Java DB documentation from Apache, it says:

Derby supports the following formats for TIMESTAMP:
yyyy-mm-dd hh[:mm[:ss[.nnnnnn]]]
yyyy-mm-dd-hh[.mm[.ss[.nnnnnn]]]


and I simply used the hh:mm format.

Hmmm... remarkable. But thanks again!
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 4088
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using the same version of derby?
 
Piet Souris
Rancher
Posts: 1943
66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I had some problems with NetBeans among other things, and a couple of days ago I downloaded both Java 1.8.0-131 and NetBeans 8.2 and installed these.
The version of the Derby database, according to the Release Notes, is 10.11.1.1. But you are right. The quote I gave seems to be from version 10.1.

I just looked at the documentation of 10.11, and it says about Timestamp:

TIMESTAMP

Dates, times, and timestamps cannot be mixed with one another in expressions.

Derby supports the following formats for TIMESTAMP:
yyyy-mm-dd hh:mm:ss[.nnnnnnnnn]
yyyy-mm-dd-hh.mm.ss[.nnnnnnnnn]
The first of the two formats above is the java.sql.Timestamp format.

So problem solved!

Again: thank you very much!

@Jeanne:
should this not be reported somewhere?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37181
515
Eclipse IDE Java VI Editor
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!