0

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.
1
  • @no.good.at.coding: Oops!! I didn't notice. Thanks. Commented May 18, 2011 at 6:04

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

@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/…
2

You need to use PreparedStatement, instead.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.