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 Relational Databases and the fly likes Formatting Oracle Date data type insert Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Formatting Oracle Date data type insert" Watch "Formatting Oracle Date data type insert" New topic
Author

Formatting Oracle Date data type insert

Joseph Smithern
Ranch Hand

Joined: Feb 11, 2006
Posts: 89
I have a Date insert that is formatted into an Oracle 9i database and it works.
But I had to make the Date variable a varchar2 in Oracle to get it to work:


I also tried pstmt.setDate(2, sub_date) with a Date data type in Oracle and I could get the date to insert but couldnt format it.

Please advise how I can get the Oracle Date datatype to work where I can also format it?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32317
    
213

Joseph,
Why not store the data as a date in the database and format it on retrieval? This would let you store it (and sort it) as a date. You could use an Oracle function to format it in the query or SimpleDateFormat after pulling it to Java. The Oracle function to_char is described here.


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Joseph Smithern
Ranch Hand

Joined: Feb 11, 2006
Posts: 89
Thanks,

It would be like this?


[ November 19, 2007: Message edited by: Joseph Smithern ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Formatting Oracle Date data type insert
 
It's not a secret anymore!