有人可以帮助我,问题是当我运行此代码时,我不断收到此语法错误:遇到" ["在第1栏第24栏。建立成功(总时间:44秒) 我无法在代码中看到我在哪里犯了错误
String id = JOptionPane.showInputDialog(null, "Please enter the Employess ID", JOptionPane.QUESTION_MESSAGE);
String fname = JOptionPane.showInputDialog(null, "Please enter Employess First NAME", JOptionPane.QUESTION_MESSAGE);
String sname = JOptionPane.showInputDialog(null, "Please enter Employess Surname NAME", JOptionPane.QUESTION_MESSAGE);
String pss = JOptionPane.showInputDialog(null, "Please enter the Employess PPS Number", JOptionPane.QUESTION_MESSAGE);
String cnum = JOptionPane.showInputDialog(null, "Please ente thr Employess Contact Number", JOptionPane.QUESTION_MESSAGE);
String address = JOptionPane.showInputDialog(null, "Please enter Employess Address", JOptionPane.QUESTION_MESSAGE);
String dep = JOptionPane.showInputDialog(null, "Please enter Employess Deparment ", JOptionPane.QUESTION_MESSAGE);
String sal = JOptionPane.showInputDialog(null, "Please enter Employess salary", JOptionPane.QUESTION_MESSAGE);
JOptionPane.showConfirmDialog(null, id + sname + "Records have been entered ");
try{
String host = "jdbc:derby://localhost/ee ";
String uName = "aa";
String uPass = "bb";
Connection con = DriverManager.getConnection(host, uName, uPass);
//Connection con = DriverManager.getConnection(host);
//Customer Lookup by Last Name
//SQL
String sql = "UPDATE emp SET fname = [?],sname = [?],pss = [?],cnum = [?],address = [?],dep = [?],sal =[?] where id = [?]";
prest = con.prepareStatement(sql);
prest.setString(1,id);
prest.setString(2,fname);
prest.setString(3,sname);
prest.setString(4,pss);
prest.setString(5,cnum);
prest.setString(6,address);
prest.setString(7,dep);
prest.setString(8,sal);
prest.executeUpdate();
}
catch (SQLException err) {
System.out.println(err.getMessage());
}
}
}
}
答案 0 :(得分:0)
参数占位符(?
)应始终紧跟等号而没有任何类型的分隔符:
String sql = "UPDATE emp SET fname=?, sname=?, pss=?, cnum=?, address=?, dep=?, sal=? WHERE id=?";
或
String sql = "UPDATE emp SET fname = ?, sname = ?, pss = ?, cnum = ?, address = ?, dep = ?, sal = ? WHERE id = ?";