vivek kumar luetel
vivek kumar luetel

Reputation: 137

while executing this sql statement in java i m getting this error

this is my sql statement in java.

//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);

this is the error:-

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.

Upvotes: 0

Views: 3527

Answers (2)

Adeel Ansari
Adeel Ansari

Reputation: 39887

You need to use PreparedStatement, instead.

Upvotes: 2

mu is too short
mu is too short

Reputation: 434585

Your problem is that you have an embedded single quote here:

+ "+ 'Employeeno doesn't exists in the database.(' + employeeno + ')' "
// -------------------^

So you end up with unbalanced single quotes and invalid SQL. You need to properly escape your text before trying to turn it into SQL.

Upvotes: 3

Related Questions