【发布时间】:2015-01-13 15:31:33
【问题描述】:
下面是我的 jFrame btn_update 代码:
private void txt_updateActionPerformed(java.awt.event.ActionEvent evt) {
try{
String Value1=txt_Emp_ID.getText();
String Value2=txt_Name.getText();
String Value3=txt_Surname.getText();
String Value4=txt_age.getText();
String Value5=txt_Username.getText();
String Value6=txt_Password.getText();
String sql = "update employee set Emp_ID=?, name=?,surname=?,age=?,username=?,password=?";
pst.setString(1, Value1);
pst.setString(2, Value2);
pst.setString(3, Value1);
pst.setString(4, Value1);
pst.setString(5, Value1);
pst.setString(6, Value1);
pst=conn.prepareStatement(sql);
rs=pst.executeQuery();
JOptionPane.showMessageDialog(null, "Updated!!");
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
和我的配置:
Connection conn=null;
ResultSet rs = null;
PreparedStatement pst = null;
当我尝试按下更新按钮时,我得到了这个:
java.sql.SQLException:Parameter index out of Range (2>参数个数,即1) 有人可以帮我吗?
【问题讨论】:
-
1) 你应该调用
conn.prepareStatement(sql)在设置它的参数。 2)您将Value1设置为您准备好的语句中的所有参数,这可能不是您想要做的。