Problems with Date, readyStatement, JDBC and PostgreSQL

I need to get a movie from a PostgreSQL database that matches the given name and release date. title is the character (75), and releaseDate is the 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 does not work because releaseDate is not suitable if needed. Query SELECT * FROM "Movie" WHERE title = A_MOVIE AND "releaseDate"= A_DATE works fine in shell using psql

+3
source share
1 answer

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

thank

+3
source

Source: https://habr.com/ru/post/1739663/


All Articles