Statement st = connect.createStatement();
String sql = "update StudentDatabaseS set RollNo = ?, FullName = ?, FatherName = ?, FatherCNIC = ?, DateOfBirth = ?, Class = ?, Address = ?, City = ?, Province = ? where RollNo = '"+Srollno+"'";
ResultSet rs = st.executeQuery(sql);
ps = connect.prepareStatement(sql);
ps.setInt(1, roll_mo);
ps.setString(2, name_mo);
ps.setString(3, Fname_mo);
ps.setString(4, fcnic_mo);
ps.setString(5, dob_mo);
ps.setInt (6, Class_mo);
ps.setString(7, add_mo);
ps.setString(8, city_mo);
ps.setString(9, prvnce_mo);
ps.executeUpdate();
I am trying to update a record in an Access database and it is continuously throwing me exceptions, for example parameter markers not allowed.
Can someone help me with this?
When
String sql = "update StudentDatabaseS set RollNo = ?, FullName = ?, FatherName = ?, FatherCNIC = ?, DateOfBirth = ?, Class = ?, Address = ?, City = ?, Province = ? where RollNo = '"+Srollno+"'";
the line
ResultSet rs = st.executeQuery(sql);
makes no sense because
executeQuery
has no way of knowing what values correspond to the parameter placeholders (?
).If you omit that line then the "parameter marker not allowed" error will go away and you can carry on with your UPDATE using the PreparedStatement.