I am trying to get data from a database in a table with 2 where parameters, When i try to execute this code it gives the error: Parameter not set. I think it is a small mistake but I can't find it. The problem could be with the 2 where parameters, i never used 2 before. Can anyone help me?
public static void tabelVullen(int Kaartnummer,int Datum){
Connection con;
try {
con = DriverManager.getConnection(DB, "", "");
PreparedStatement s = con.prepareStatement("Select Kaartnummer, Datum, Maaltijd, Prijs FROM Logbestanden WHERE Kaartnummer=? AND Datum=?");
s.setInt(1, Kaartnummer);
rset = s.executeQuery();
while(rset.next()){
String[] Logboek = new String[4];
Logboek[0]=rset.getString("Kaartnummer");
Logboek[1]=rset.getString("Datum");
Logboek[2]=rset.getString("Maaltijd");
Logboek[3]=rset.getString("Prijs");
model.addRow(Logboek);
}
s.close();
con.close();
} catch (SQLException e) {
System.out.println("Error LogbestandenWeergeven: " + e);
}
}
This is the error
Error LogbestandenWeergeven: net.ucanaccess.jdbc.UcanaccessSQLException: Parameter not set
You just need to supply a second parameter for the Datum value:
PreparedStatement s = con.prepareStatement("Select Kaartnummer, Datum, Maaltijd, Prijs FROM Logbestanden WHERE Kaartnummer=? AND Datum=?");
s.setInt(1, Kaartnummer);
s.setInt(2, Datum); // this is what you are missing
rset = s.executeQuery();