If you have your PreparedStatement with an SQL query as you stated you can do:
int yourID = 1;
String tablename = "table";
String query = "SELECT * FROM " + tableName + " where id = ?";´
PreparedStatement statement = con.prepareStatement(query);
statement.setInt(1, yourID);
It will replace the ?
with 1
. If you have multiple ?
you can set those like
statement.setString(2, "YourString");
Check
http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html for more Information.