PreparedStatement
Får en fejl ved følgende stykke kode:public void addReservation(int a, int b, int c, int d, Date f, Date g, int h) {
try {
String q = "INSERT INTO reservation (CustID,RID,PriceID,Staff ID,CheckinDate,CheckoutDate,#weeks) VALUES (?, ?, ?, ?, ?, ?, ?)";
PreparedStatement Stmt = db.prepareStatement(q);
Stmt.setInt(1, a);
Stmt.setInt(2, b);
Stmt.setInt(3, c);
Stmt.setInt(4, d);
Stmt.setDate(5, f);
Stmt.setDate(6, g);
Stmt.setInt(7, h);
Stmt.executeUpdate();
}
catch (SQLException e) {
e.printStackTrace();
}
}
Fejlen er at den ikke ser de spørgsmålstegn, men hvorfor?
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
at com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3717)
at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3701)
at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3743)
at com.mysql.jdbc.PreparedStatement.setInt(PreparedStatement.java:3687)
at DbConnections.addReservation(DbConnections.java:197)
at CottageGui$1.actionPerformed(CottageGui.java:95)