Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cannot insert datetime type

 
pingkan paula
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,

I want to move all data that last 7 days before current date to other database, therefore i'm using two connection to select and insert the data.
The problem is I can't insert datetime type into the table, it appears as 0000-00-00 00:00:00 when I checked it. I tried to parse using SimpleDateFormat
but still not working.
This is the snippet


Any idea?
 
Eduardo Dela Rosa
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Sometimes it's hard to guess the cause of problem. Can you possibly include
the stack trace of the exception you've got? That way, we'll easily pin point
where the problem is coming from, hence possible solution can be provided.

But initially, you might not be getting any results at all in your ResultSet
object. Besides, you can simply use Statement, rather than PreparedStatement
because you're not using or setting any parameters to your query anyway.

Cheers!
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by pingkan paula:

The problem is I can't insert datetime type into the table, it appears as 0000-00-00 00:00:00 when I checked it. I tried to parse using SimpleDateFormat
but still not working.








Is there any specific reason for which you are inserting date as string after converting it to specific format. Are you sure there is no exception.

I guess you data type of column is date not String



Shailesh
 
pingkan paula
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The column value is dateTime, I use string to insert the data because it didn't work with with the value coming from rs.getDate()
This is the output from my console



This is the snippet code

 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead ofwhy not forget about converting to and from strings and just do this:
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by pingkan paula:
The column value is dateTime, I use string to insert the data because it didn't work with with the value coming from rs.getDate()


Could you explain this, What I can guess is when you are calling rs.getDate() you are loosing time part of your date? Or is there something else which didn't work for you.



database errorjava.sql.SQLException: Duplicate entry '628151308255020050901000153496-nRn2Rkp4c01' for key 1


Did you try to trace for this error ? you are inserting a duplicate key in your table. What is primary keys on your table.

Shailesh
[ April 11, 2006: Message edited by: Shailesh Chandra ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic