Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

PreparedStatement and setDate

843854Aug 24 2004 — edited Aug 26 2004
Hello. I've been going at this for pretty much the day today and I keep running into the same wall. I am hitting an Oracle table that stores all the date fields as varchar2 in this format...15-JAN-2004.

I am kinda messing around wiht doing date range searches on the table and I've been working my way through it but I think I keep puking on trying to input the month as JAN, FEB, etc. I a trying a PreparedStatement in the follwoing way to handle my input parameter (hard coded here as an input string "05-AUG-2002")...and to_date within the SQL statement to hopefully read the DATE_CREATED record field as a date (again, this field is varchar2 stored as "15-JAN-2004", etc). I now keep getting an unparseable exception on "05-AUG-2002" when I try to parse it...

String SQFinal = "SELECT DATE_CREATED "
+ "FROM INVOICES "
+ "WHERE "
+ "DB_SOURCE = 'AX' "
+ "AND STATUS = 'PENDING' "
+ "AND to_date(DATE_CREATED,'dd-mmm-yyyy') < ? "
+ "ORDER BY CONTROL_NO DESC";

...jdbc statements here...

stmt=conn.createStatement();

String strNow = "05-AUG-2002";
SimpleDateFormat sdf = new SimpleDateFormat("dd-mmm-yyyy");

java.util.Date dtNow = sdf.parse(strNow);

java.sql.Date dtNowSQL = new java.sql.Date(dtNow.getTime());

PreparedStatement ps = conn.prepareStatement(SQFinal);

ps.setDate(1,dtNowSQL);

rs=ps.executeQuery();

Thanks to combing through old posts in this forum and elsewhere, I've been able to get this to compile. I was having problems with the java.util.Date and java.sql.Date messing wiht each other...but I can't find anything on this weried date format I want to query.

Thank you very much for reading...any input at this point would be really appreciated.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 23 2004
Added on Aug 24 2004
16 comments
2,988 views