这是我在java中的sql语句。
//validating for employee no exits in database or not
String importTable = getConfig().getImportTable();
String sql = "update "
+ importTable
+ " set errMsg = case when errMsg is null or errMsg ='' then '' else errMsg + '<br>' end "
+ "+ 'Employeeno doesn't exists in the database.(' + employeeno + ')' "
+ " where employeeno is not null and not exists (select * from uae_empinfo where employee = "
+ importTable + ".cid)";
executeCommand(sql);
这是错误:-
org.springframework.dao.DataIntegrityViolationException: StatementCallback; SQL []; Invalid SQL statement or JDBC escape, terminating ''' not found.; nested exception is java.sql.SQLException: Invalid SQL statement or JDBC escape, terminating ''' not found.
最佳答案
您的问题是这里嵌入了单引号:
+ "+ 'Employeeno doesn't exists in the database.(' + employeeno + ')' "
// -------------------^
所以你最终会得到不平衡的单引号和无效的 SQL。在尝试将文本转换为 SQL 之前,您需要正确转义文本。
关于java - 在java中执行这个sql语句时我收到这个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6039882/