java - 在java中执行这个sql语句时我收到这个错误

标签 java sql

这是我在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/

相关文章:

java - DataNucleus + JDO : Retrieve an object with Composite Key (error:NoSuchElementException)

java - 从命令行编译带有两个 jar 的 java 文件?

Java List.addAll 使用集合的流而不是使用集合本身?

python - 如何在 SQL 数据库中存储 python float

sql - 从另一个表创建一个表

java - 椭圆曲线加密

java - 如何在JOOQ中通过复合主键选择多行?

mysql - SQL Server与MySQL

php - SQL Server PDO UPDATE 循环错误

sql - 尝试确定特定零件号的下一个机器操作是什么