Date comparison in PreparedStatement gives Invalid column index Exception
When I set a date parameter in a PreparedStatement I get this Exception:
java.sql.SQLException: Invalid column index
Here's the code:
GregorianCalendar gc = new GregorianCalendar();
gc.set(Calendar.HOUR_OF_DAY, 6);
gc.set(Calendar.MINUTE,0);
gc.set(Calendar.SECOND,0);
String sql =
"SELECT notes FROM JOBQUEUE" +
" WHERE userkey='?' AND" +
" EXECUTE='buildGraph' AND" +
" request_stamp > ?";
try {
Connection c = getConnection();
PreparedStatement ps = c.prepareStatement(sql);
String userName = user.getUserName();
ps.setString(1, userName);
ps.setDate(2, new java.sql.Date(gc.getTimeInMillis()));
....
The setDate() call throws the SQLException above. Is there something wrong with doing a date comparison with the '>' operator in a PreparedStatement?
I'd like to avoid the ugliness of converting my Date back into a String and using to_date(). I thought that PreparedStatement was supposed to avoid all of this conversion nonsense.
Thanks.
Dean