0

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?

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by chicago1985
0

what do you mean "but you couldn't format it"?
A Date's a Date. There's no need to format anything when working with a Date internally.
Only when presenting it for output may you want to perform formatting.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.