public int isInfod(Vacancy vacancy, String table, String collumn) { try (PreparedStatement statement = conn.prepareStatement("SELECT ID FROM ? WHERE ? = ?")) { statement.setString(1, table); statement.setString(2, collumn); statement.setString(3, vacancy.getAuthor()); statement.executeQuery(); } catch (SQLException e) { e.printStackTrace(); } return 0; 

such a request produces errors, i.e. Do I get to write a separate query for each table and column? I have essentially the same request,

  • one
    The table name cannot be set by wildcard characters. - Sergey Gornostaev
  • 2
    And the field name is also impossible. It is possible to use the procedure with the prepared statement, of course - but this requires checking the table and collumn variables for validity (by a request to the schema). I actually have the same request and the same of the 4 changeable characteristics of the request, only one is constant, and three are changing ... a very strange understanding of the expression "the same" ... - Akina
  • 2
    The need for this often signals architectural problems. - Hivemaster
  • It is possible and not separate. The request in this case is a regular line, so it can be assembled from parts. You just need to remember to check that there were no invalid characters in the names of tables and columns that break the query - Mike
  • It turns out that all your requests are nailed to a certain type of Vacancy . Do you have a field in each table where the Author is stored? - Alexander Petrov

0