Reputation: 137
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
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