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 java.sql getTimestamp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.sql getTimestamp" Watch "java.sql getTimestamp" New topic
Author

java.sql getTimestamp

Kee Kee moon
Ranch Hand

Joined: Dec 11, 2009
Posts: 147
I have a table with a column date that contains the date format like 2009-10-10 12:11:51.140

And I need to select the date as above 2009-10-10 12:11:51.140 and insert into another table. So here is my code, but I got errors
ORA-01847: day of month must be between 1 and last day of month

Stmt.setTimestamp(1, result.getTimestamp("date"));

Do I miss anything?
Thanks.
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

If your column is dateTime and not timestamp, why bother with timestamp at all?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Moving to JDBC.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Kee Kee moon
Ranch Hand

Joined: Dec 11, 2009
Posts: 147
Tim McGuire wrote:If your column is dateTime and not timestamp, why bother with timestamp at all?


What should I do in order to get the dateTime 2009-10-10 12:11:51.140 inserted into another table?

Thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

You should bear in mind that we don't know what your PreparedStatement looks like. And that we don't know anything about this table and what type of column you're trying to use. (Actually, not true: we know it's in an Oracle database.)

So absent that useful information I would suggest you try to insert it only in a column which is set up to receive timestamp information. And don't write SQL which tries to convert it to some other format; let the database driver take care of formatting.
Kee Kee moon
Ranch Hand

Joined: Dec 11, 2009
Posts: 147
Paul Clapham wrote:You should bear in mind that we don't know what your PreparedStatement looks like. And that we don't know anything about this table and what type of column you're trying to use. (Actually, not true: we know it's in an Oracle database.)

So absent that useful information I would suggest you try to insert it only in a column which is set up to receive timestamp information. And don't write SQL which tries to convert it to some other format; let the database driver take care of formatting.




What should I do in order to get the dateTime 2009-10-10 12:11:51.140 inserted into another table?

on the inserting table the datatype is DATE, inserting into a Oracle 10.0.2.0.1 database table.
on the retrieving table is a sqlserver and the datatype is datetime, the data is like 2009-10-10 12:11:51.140

I have changedto Stmt.setString(1, rs.getString("date")); However, I got an error as ORA-01861: literal does not match format string

Thanks

Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2503
    
    8

Hi, Kee Kee,

we were trying to get you on trach here:
http://www.coderanch.com/t/490526/JDBC/java/setNull-java-sql-Types-DATE#2206497

Have you tried the suggestions of that thread?


OCUP UML fundamental and ITIL foundation
youtube channel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.sql getTimestamp