Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 通过JFrame表单更新MySQL数据库,同时刷新JFrame表单上的J表_Java_Mysql - Fatal编程技术网

Java 通过JFrame表单更新MySQL数据库,同时刷新JFrame表单上的J表

Java 通过JFrame表单更新MySQL数据库,同时刷新JFrame表单上的J表,java,mysql,Java,Mysql,我开发了上面的表单,用于更新MySQL数据库表“employeeinfo”。表单还显示了一个J表,其中包含数据库表“employeeinfo”中的当前数据 我编码以选择J表行,并将表行中的内容添加到表单中的相关文本字段中 但是,我在通过编辑选定的员工来更新MySQL数据库时遇到了问题……**当我编辑文本字段并点击“更新”时,数据库或Jtable没有更新** 数据库未更新且J表未刷新..(可能是因为数据库表未更新) 执行更新按钮操作 private void update_btnActionPer

我开发了上面的表单,用于更新MySQL数据库表“employeeinfo”。表单还显示了一个J表,其中包含数据库表“employeeinfo”中的当前数据

我编码以选择J表行,并将表行中的内容添加到表单中的相关文本字段中

但是,我在通过编辑选定的员工来更新MySQL数据库时遇到了问题……**当我编辑文本字段并点击“更新”时,数据库或Jtable没有更新**

数据库未更新且J表未刷新..(可能是因为数据库表未更新)

执行更新按钮操作

private void update_btnActionPerformed(java.awt.event.ActionEvent evt) {                                           

try{
    String val1 =txt_id.getText();
    String val2 =txt_name.getText();
    String val3 =txt_sname.getText();
    String val4 =((JTextField)bday_chooser.getDateEditor().getUiComponent()).getText();
    String val5 =((JTextField)wday_chooser.getDateEditor().getUiComponent()).getText();

    String sql = "update employeeinfo set EmployeeID='"+val1+"',Name='"+val2+"',Surname='"+val3+"', BirthDate='"+val4+"',WorkStartedDate='"+val5+"' where EmployeeID='"+val1+"' ";

    pst=conn.prepareStatement(sql);
    pst.execute();

    JOptionPane.showMessageDialog(null, "User Data Updated...");

}catch(Exception e){
    JOptionPane.showMessageDialog(null, e);
}
updateTable();}           
可更新方法

private void updateTable(){

try {
    String sql = "SELECT * FROM employeeinfo";
    pst=conn.prepareStatement(sql);
    rs=pst.executeQuery();
    table_empinfo.setModel(DbUtils.resultSetToTableModel(rs));
} catch (Exception ex) {
    JOptionPane.showMessageDialog(null, "Error : "+ex);
}}

看起来有点奇怪,您使用val1更新EmployeeID,并且在同一过程中使用此值来标识必须更新的条目。。。你知道我的意思吗?您必须使用旧的EmployeeID来更新数据库中的正确行。@Stefan Beike这是错误:)现在它可以工作了…谢谢您的评论:)您使用val1更新EmployeeID看起来有点奇怪,在同一过程中,您使用此值来标识必须更新的条目。。。你知道我的意思吗?您必须使用旧的EmployeeID来更新数据库中的正确行。@Stefan Beike这是错误:)现在它可以工作了……谢谢您的评论:)