使用SQL Server更新Java中的异常查询

时间:2013-03-13 10:28:39

标签: java sql-server-2008

PreparedStatement update = con.prepareStatement(
    "UPDATE employee SET FirstName = ?, LastName = ?, HighestDegreeEarned = ?, JoiningDate = ?, CurrentPost = ?, DeparmentID = ?, ContactNo(Mobile) = ?, ContactNo(Home) = ?, CurrentAddress = ?, PermanentAddress = ? WHERE ID =  ?");

update.setString(1, firstnametxt.getText());
update.setString(2, lastnametxt.getText());
update.setString(3, degreetxt.getText());
update.setString(4, joiningdatetxt.getText());
update.setString(5, currentposttxt.getText());
update.setString(6, departmentidtxt.getText());
update.setString(7, mobiletxt.getText());
update.setString(8, contactnotxt.getText());
update.setString(9, currentaddresstxt.getText());
update.setString(10, permanentaddresstxt.getText());
update.setString(11, empidtxt.getText());

update.executeUpdate();

这里是代码并且在exexuting上我得到下面的错误。 SQL异常:java.sql.SQLException:[Microsoft] [ODBC SQL Server驱动程序] [SQL Server]')'附近的语法不正确。请帮助我

2 个答案:

答案 0 :(得分:0)

数据库中的列不能命名:ContactNo(Mobile)或ContactNo(Home)

如果ContactNo()是一个函数,请使用动态sql来调用它。

答案 1 :(得分:0)

失败可能有两个原因

  1. SQL Server中的ContactNo函数未退出或未编译
  2. JoiningDate格式不正确