File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes cannot insert datetime type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "cannot insert datetime type " Watch "cannot insert datetime type " New topic
Author

cannot insert datetime type

pingkan paula
Ranch Hand

Joined: Sep 03, 2004
Posts: 117
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

Joined: Apr 15, 2004
Posts: 25
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!


Eduardo dela Rosa<br />SCJP 1.4
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

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


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
pingkan paula
Ranch Hand

Joined: Sep 03, 2004
Posts: 117
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Instead ofwhy not forget about converting to and from strings and just do this:
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

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 ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: cannot insert datetime type