Discussion Locked

Java - Date variables and SQL ResultSet

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am running an SQL query in my Java program which returns a date variable as part of the resultset. I then try to assign this value to another Date variable and use in a subsequent query but receive error messages in relation to syntax
Some samplecode:
java.util.Date d1 = rs3.getDate(1);

ResultSet rs1 = myDB2.Select2("select * from worksheet where worksheet.work_date = " + d1 + " order by worksheet.work_date");

If anybody has any suggestions I would be most grateful for any assistance

1 reply

by nikki96

Use java.sql.Date instead of java.util.Date.

This assumes your field was declared as a date type, not a string and that this is not Access. Access needs dates surrounded by pound signs inside queries.

This discussion is closed to new replies.