我正在尝试从 JTable 中检索数据,然后使用它来更新保存在数据库中的 sql 表。但是,java给了我这个错误,
ORA-01861: literal does not match format string
我试图包含不同的字符串并且它有效,但对于这种情况,它没有。有人可以帮忙吗?这是我的代码,
for(int i=0; i<size; i++)
{
Object fname= searchResultTable.getModel().getValueAt(i,0);
Object lname= searchResultTable.getModel().getValueAt(i,1);
Object minit= searchResultTable.getModel().getValueAt(i,2);
Object SSN = searchResultTable.getModel().getValueAt(i,3);
Object birthDate=searchResultTable.getModel().getValueAt(i,4);
Object address = searchResultTable.getModel().getValueAt(i,5);
Object sex = searchResultTable.getModel().getValueAt(i,6);
Object salary = searchResultTable.getModel().getValueAt(i,7);
Object superSSN = searchResultTable.getModel().getValueAt(i,8);
Object dno = searchResultTable.getModel().getValueAt(i,9);
// Statement S = conn.createStatement();
// String query ="UPDATE EMPLOYEE SET fname='"+fname+"', lname='"+lname+"', minit='"+minit+"', ssn='"+SSN+"', bdate='"+birthDate+"', address='"+address+"', sex='"+sex+"', salary='"+salary+"', superssn='"+superSSN+"', dno='"+dno+"' WHERE ssn='"+ssn.get(i)+"' ";
// query="UPDATE EMPLOYEE set fname='Ray',lname='King' where fname='Ray' and lname='King' ";
String query ="UPDATE EMPLOYEE SET fname=?, lname=?, minit=?, ssn=?, bdate=?, address=?, sex=?, salary=?, superssn=?, dno=? WHERE ssn=?";
try{
PreparedStatement S = conn.prepareStatement(query);
S.clearParameters();
S.setString(1,fname.toString());
S.setString(2, lname.toString());
S.setString(3, minit.toString());
S.setString(4, SSN.toString());
S.setString(5, birthDate.toString());
S.setString(6,address.toString());
S.setString(7, sex.toString());
S.setString(8, salary.toString());
S.setString(9, superSSN.toString());
S.setString(10,dno.toString());
S.setString(11, ssn.get(i));
System.out.println(fname+", "+lname+","+salary);
int count= S.executeUpdate();
JOptionPane.showMessageDialog(this, "Employee Table Was Updated Successfully");
}catch(SQLException sqle){System.out.println(sqle.getMessage());}
}
}