Using preparedStatement in Java/MariaDb as in the following function
public ArrayList<String> findPath(String roomName) throws SQLException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException
{
ArrayList<String> path = new ArrayList<String>();
connection = getConnection();
String queryPattern = "SELECT `Livello_1`, `Livello_2`, `Livello_3`, `Livello_4` FROM Camera WHERE Camera.Nome = '?'";
PreparedStatement queryStatement = connection.prepareStatement(queryPattern);
queryStatement.setString(1, roomName);
ResultSet rs = queryStatement.executeQuery();
if(rs.next())
{
for(int i = 0; i < 3; i++)
{
path.add(rs.getString(i));
}
}
return path;
}
I obtain the error message:
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
and the error line number points to line
queryStatement.setString(1, roomName);
'?'. And stop using`for your column names, they are not necessary.'?'counts as a literal questionmark, not a placeholder for paramters.