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.
Howard
39.3k9 gold badges68 silver badges85 bronze badges
asked May 18, 2011 at 4:30
vivek kumar luetel
1372 gold badges4 silver badges11 bronze badges
-
@no.good.at.coding: Oops!! I didn't notice. Thanks.Adeel Ansari– Adeel Ansari2011年05月18日 06:04:43 +00:00Commented May 18, 2011 at 6:04
2 Answers 2
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.
answered May 18, 2011 at 4:36
mu is too short
436k71 gold badges863 silver badges822 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
no.good.at.coding
@vivek I fail to understand why you've not accepted this answer or any of the others in your previous questions. Are you unaware of how to do so? Please see meta.stackexchange.com/questions/5234/…
You need to use PreparedStatement, instead.
answered May 18, 2011 at 4:38
Adeel Ansari
39.9k12 gold badges98 silver badges135 bronze badges
Comments
default