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
The problem was in the database because of time format was changed from dd/MM/YYYY to MM/dd/YYYY.
Thanks
精彩评论