Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / November 2007

Tip: Looking for answers? Try searching our database.

Oracle Date data type insert and format

Thread view: 
teser3@hotmail.com - 20 Nov 2007 00:24 GMT
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:

.....
java.sql.Timestamp myd = new java.sql.Timestamp(new
java.util.Date().getTime());
String sub_date = new SimpleDateFormat("mm/dd/yy , h:mm
a").format(myd);
String query = "insert into dept(location, sub_date) values(?, ?)";
PreparedStatement pstmt =
conn.prepareStatement(query);
pstmt.setString(1, "Jersey");
pstmt.setString(2, sub_date);
pstmt.executeUpdate();
......

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?
teser3@hotmail.com - 20 Nov 2007 01:59 GMT
On Nov 19, 7:24 pm, "tes...@hotmail.com" <tes...@hotmail.com> wrote:
> I have a Date insert that is formatted into an Oracle 9i database and
> it works.
[quoted text clipped - 19 lines]
> Please advise how I can get the Oracle Date datatype to work where I
> can also format it?

I also tried pstmt.setTimestamp(2, sub_date) and it didnt format
also.  Please advise.
Arne Vajhøj - 20 Nov 2007 02:35 GMT
> On Nov 19, 7:24 pm, "tes...@hotmail.com" <tes...@hotmail.com> wrote:
>> I have a Date insert that is formatted into an Oracle 9i database and
[quoted text clipped - 23 lines]
> I also tried pstmt.setTimestamp(2, sub_date) and it didnt format
> also.

pstmt.setTimestamp is the correct solution to insert a Timestamp
in a DATE column.

Try show us the code you use and the exception you get.

Arne


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.