samedi 7 mai 2016

Select with prepared statements Java

I just learned about prepared statements and now I'm trying to include them to my java program. However I get an exception when I try to add to values to the statement( table and name). When I prepare with only one variable it works fine. What am I doing wrong?

[SQLITE_ERROR] SQL error or missing database (near "?": syntax error) 


String sql="SELECT * FROM ? WHERE name = ?";
    try {
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, table);
        preparedStatement.setString(2, name);
        ResultSet checkTable = preparedStatement.executeQuery();

Aucun commentaire:

Enregistrer un commentaire