Reputation: 544
Java DB2 Sql command throws an error if i have a '
in my String i tried to replace it with a escape sequence but it would not work on the DB2 end any help ? I want the '
to be present in the String.
Error
com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-10, SQLSTATE=42603, SQLERRMC=', DRIVER=3.63.123
Java
String FUNC_VP = "Chris O'Connor/Henry/George";
String myQuery = "SELECT DISTINCT(VICE_PRES) FROM EMP_HC WHERE FUNC_VP ='"+funcvp_name.replace("'", "/'")+"'";
Upvotes: 0
Views: 1295
Reputation: 73568
Use a PreparedStatement
and its setParameter()
methods. It will handle things like escaping for you, and you'll never have to wonder how a particular database might handle things. It also prevents SQL injection, so there's no good reason not to use it.
Upvotes: 8
Reputation: 7335
Try
String FUNC_VP = "Chris O''Connor/Henry/George";
To escape an apostrohe on DB2 it seems you have to use two apostrophes
Upvotes: 1