JAVA中在同一事件中执行两条SQL语句,只有第一条执行。 30
编译没有问题只执行了第一条SQL语句即ssql(之前定义了),后一条SQL语句即ssql_1没有执行。但是把第二句的?改成一个具体的房间号(并把那个于?相关的赋值语句删除...
编译没有问题只执行了第一条SQL语句即ssql(之前定义了),后一条SQL语句即ssql_1没有执行。但是把第二句的?改成一个具体的房间号(并把那个于?相关的赋值语句删除)就能执行两个。哪里有问题?数据库之前连的。
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try{
ssql="INSERT INTO inout VALUES(?,?,?,?,?)";
ps=cn.prepareStatement(ssql);
ps.setString(1,textField.getText());
ps.setString(2,textField_1.getText());
ps.setString(3,textField_2.getText());
ps.setString(4,textField_3.getText());
ps.setInt(5, Integer.parseInt(textField_4.getText()));
ps.executeUpdate();
lblNewLabel.setText("succeed");
textField_1.setText("");
textField_2.setText("");
textField_3.setText("");
textField_4.setText("");
textField.setText("");
textField.requestFocus();
ps.close();
}catch(Exception e2){
lblNewLabel.setText("error in data inserting");
textField.requestFocus();
}
try{
ssql_1="UPDATE rooms SET 是否有客='是' WHERE 房间号=?";
PreparedStatement ps_1=cn.prepareStatement(ssql_1);
ps_1.setString(1,textField.getText());
ps_1.executeUpdate();
lblNewLabel.setText("succeed in num update");
}catch(Exception e2){
lblNewLabel.setText("error in num update");
textField.requestFocus();
}
}
}); 展开
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try{
ssql="INSERT INTO inout VALUES(?,?,?,?,?)";
ps=cn.prepareStatement(ssql);
ps.setString(1,textField.getText());
ps.setString(2,textField_1.getText());
ps.setString(3,textField_2.getText());
ps.setString(4,textField_3.getText());
ps.setInt(5, Integer.parseInt(textField_4.getText()));
ps.executeUpdate();
lblNewLabel.setText("succeed");
textField_1.setText("");
textField_2.setText("");
textField_3.setText("");
textField_4.setText("");
textField.setText("");
textField.requestFocus();
ps.close();
}catch(Exception e2){
lblNewLabel.setText("error in data inserting");
textField.requestFocus();
}
try{
ssql_1="UPDATE rooms SET 是否有客='是' WHERE 房间号=?";
PreparedStatement ps_1=cn.prepareStatement(ssql_1);
ps_1.setString(1,textField.getText());
ps_1.executeUpdate();
lblNewLabel.setText("succeed in num update");
}catch(Exception e2){
lblNewLabel.setText("error in num update");
textField.requestFocus();
}
}
}); 展开
3个回答
展开全部
ps.setString(1,textField.getText());
ps.setString(2,textField_1.getText());
ps.setString(3,textField_2.getText());
ps.setString(4,textField_3.getText());
ps.setInt(5, Integer.parseInt(textField_4.getText()));
你要输入的应该是
ps.setString(0,textField.getText());
ps.setString(1,textField_1.getText());
ps.setString(2,textField_2.getText());
ps.setString(3,textField_3.getText());
ps.setInt(4, Integer.parseInt(textField_4.getText()));
这样吧???
你只有5格 计算值是0开始不是1喔!!!
ps.setString(2,textField_1.getText());
ps.setString(3,textField_2.getText());
ps.setString(4,textField_3.getText());
ps.setInt(5, Integer.parseInt(textField_4.getText()));
你要输入的应该是
ps.setString(0,textField.getText());
ps.setString(1,textField_1.getText());
ps.setString(2,textField_2.getText());
ps.setString(3,textField_3.getText());
ps.setInt(4, Integer.parseInt(textField_4.getText()));
这样吧???
你只有5格 计算值是0开始不是1喔!!!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询