3

I Have to get a movie from a PostgreSQL database that matches a given title and release date. title is a character(75) and releaseDate is a date. I Have this code:

String query = "SELECT * FROM \"Movie\" WHERE title = ? AND \"releaseDate\" = ?)";
Connection conn = connectionManager.getConnection();
PreparedStatement stmt = conn.prepareStatement(query);
java.sql.Date date = new java.sql.Date(releaseDate.getTime());
stmt.setString(1, title);
stmt.setDate(2, date);
ResultSet result = stmt.executeQuery();

but it's not working because the releaseDate is not matching when it should. The query SELECT * FROM "Movie" WHERE title = A_MOVIE AND "releaseDate" = A_DATE works perfectly on a command shell using psql

3
  • If releaseDate is a java.sql.Date, why copy it to date before calling setDate()? Commented Apr 3, 2010 at 4:07
  • is not java.sql.Date is java.util.Date Commented Apr 3, 2010 at 4:10
  • 1
    What's the exact SQL column type of releaseDate? Is it really date? There is also timestamp. Which PostgreSQL DB version and JDBC driver version are you using? Commented Apr 3, 2010 at 4:11

1 Answer 1

3

The problem was in the database because of time format was changed from dd/MM/YYYY to MM/dd/YYYY.

Thanks

Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.