• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

cannot insert datetime type

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead ofwhy not forget about converting to and from strings and just do this:
 
Shailesh Chandra
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic