There is such code:

PreparedStatement statement = null; ResultSet result = null; String query = "SELECT passenger_id, name, surname, dateOfBirth FROM passengers " + " WHERE passenger_id IN " + " (SELECT passenger_id FROM tickets " + " WHERE bus_id=?)"; statement = connection.prepareStatement(query); statement.setInt(1, bus.getBusId()); result = statement.executeQuery(query); 

The query should return the table, and it works if executed from the MySQL console. However, when trying to execute a program, the following error occurs: enter image description here

I would be grateful for the help.

  • and where exactly does the error occur, on prepare or not execute? - rjhdby
  • @rjhdby when calling executeQuery () - PashaKrizskiy
  • @rjhdby If you remove the sign? and statement.setInt (), then everything works, the problem is that? is recognized as an incorrect syntax, and not as a place where you need to substitute an int ... - PashaKrizskiy
  • one
    change to result = statement.executeQuery(); - rjhdby
  • @rjhdby As I myself did not notice ... Thank you! : D - PashaKrizskiy

0