| Author |
Insert a date to Oracle - an Example please!!!
|
John Tyll
Greenhorn
Joined: Feb 06, 2003
Posts: 10
|
|
Hello, Yes I am new to Java and dates are driving me nuts Anyway, here's the background: I am selecting information from one Oracle DB, doing a little manipulation and inserting to a different Oracle DB. My problem: Several of the columns I select are dates and need to be inserted to this other Oracle DB. I have tried 5 or 6 different ways and end up with as many errors (java won't compile 'unclosed character literal', Oracle thinks it is a the column name not a date, Oracle say's format is to long, etc...). My display in Java shows the date as '2003-02-25 16:13:19.0'. I have removed the .0 with substring and stringTokenizer, but still didn't get it to work. PLAEASE PLEASE PLEASE: Show me an example of how you would insert this type of date from a variable (NOT hard coded) to Oracle. NOTE: My code works just fine if I plug a date but I need the one I selected from the other DB. Many Thanks!
|
 |
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
|
|
Have you tried to use a PreparedStatement? It has a setDate method that takes a java.sql.Date argument and would seem to be pretty easy to use. [ March 26, 2003: Message edited by: Dirk Schreckmann ]
|
[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
|
 |
Leslie Chaim
Ranch Hand
Joined: May 22, 2002
Posts: 336
|
|
Use a PreparedStatement as Dirk suggested, and... the SQL should be: say you have your clean value (with the '.0' removed) in dateString: The rest, I hope, is simple. Cheers,
|
Normal is in the eye of the beholder
|
 |
SJ Adnams
Ranch Hand
Joined: Sep 28, 2001
Posts: 925
|
|
Leslie, You've misunderstood what Dirk is saying. insert into some_table(some_data_column)values(?) stmt.setDate(1, myDateObject); there is no reason to parse date strings!
|
 |
John Tyll
Greenhorn
Joined: Feb 06, 2003
Posts: 10
|
|
|
Thanks, That is just what I needed...
|
 |
 |
|
|
subject: Insert a date to Oracle - an Example please!!!
|
|
|