• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.sql.Date '0000-00-00' problem

 
Giuseppa Cefalu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I run into this problem: Value ‘0000-00-00’ can not be represented as java.sql.Date; In some cases there is no date to input in the database and the input is null. Is there any way to solve this?

Thank you,
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65342
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not just use a null?
 
Paul Clapham
Sheriff
Posts: 21586
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I pasted the error message into Google I got more than one page of results. The first four results from the top of my list all had the same recommendation. Here's the most concise version: http://community.eapps.com/showthread.php?8-Value-0000-00-00-cannot-be-represented-as-java.sql.Date.
 
Giuseppa Cefalu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. My editbale JTable returns null if there is not a date value in the database; and I store null in the database for any missing data; but I get the error message as if I had stored "0000-00-00" or as if the table returned "0000-00-00"

I am going to try to understand this: The JDBC driver developers for MySQL created an option for how '0000-00-00' dates should be handled (since that technically isn't a valid date from Java's standpoint). Even though this is the default value for NOT NULL date fields in MySQL, they decided to default this option to throw an exception. You can in fact change this behavior to the more sensible option of just returning null. To do this, add "zeroDateTimeBehavior=convertToNull" to the end of the "url" parameter in the server.xml connection pool resource section. Here's what the end product should look like:


 
Giuseppa Cefalu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. You are rigth guys. I made a change in my JTable and it accidentaly change the database value from null to "0000-00-00"; the prole is with the JTable then. Do you handle JTable questions as well or showld I pose the question to the SWING guys?

Than you
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65342
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swing questions should be posted in the Swing forum.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic