• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Insert a date to Oracle - an Example please!!!

 
John Tyll
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
SJ Adnams
Ranch Hand
Posts: 925
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, That is just what I needed...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic