Problems with Date, preparedStatement, JDBC and PostgreSQL
Posted
by GuidoMB
on Stack Overflow
See other posts from Stack Overflow
or by GuidoMB
Published on 2010-04-03T03:06:39Z
Indexed on
2010/04/03
3:13 UTC
Read the original article
Hit count: 491
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
© Stack Overflow or respective owner