java sql exception parameter not set

放肆的年华 提交于 2019-12-20 02:09:12

问题


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

回答1:


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();


来源:https://stackoverflow.com/questions/29869073/java-sql-exception-parameter-not-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!