jQuery.toggle
我正在尝试更新Access数据库中的记录,并且它不断地向我抛出异常,例如不允许使用参数标记。
有人可以帮我这个吗?
答案 0 :(得分:2)
当
String sql = "update StudentDatabaseS set RollNo = ?, FullName = ?, FatherName = ?, FatherCNIC = ?, DateOfBirth = ?, Class = ?, Address = ?, City = ?, Province = ? where RollNo = '"+Srollno+"'";
行
ResultSet rs = st.executeQuery(sql);
没有意义,因为
executeQuery
无法知道哪些值与参数占位符(?
)对应。如果省略该行,则“参数标记不允许”错误将消失,您可以使用PreparedStatement继续更新。
答案 1 :(得分:0)
try{
Statement st = connect.createStatement();
String sql = "update StudentDatabaseS set RollNo = ?, FullName = ?, FatherName = ?, FatherCNIC = ?, DateOfBirth = ?, Class = ?, Address = ?, City = ?, Province = ? where RollNo = '"+Srollno+"'";
try {
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();
Toolkit.getDefaultToolkit().beep();
JOptionPane.showMessageDialog(null, "Record Modified !");
search_input.requestFocus();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
catch(Exception e)
{
Toolkit.getDefaultToolkit().beep();
JOptionPane.showMessageDialog(null, e);
}