I have a Java class where I construct SOQL queries using String
concatenation.
Is there any best practice which someone can suggest to escape SOQL special characters like single quotes?
I have a Java class where I construct SOQL queries using String
concatenation.
Is there any best practice which someone can suggest to escape SOQL special characters like single quotes?
I am sorry, I misunderstood the problem, My bad.
Here is the solution:
1.Use prepared Statement.
String data="a'b";
String stmt = " INSERT INTO student (column_name) VALUES (?)";
PreparedStatement statement= con.prepareStatement(stmt);
statement.setString(1,data);
statement.executeUpdate();
2.Escape the single quotes. Single quotes can be escaped by using double single quotes. ' --> ''
String data="a'b";
String changedUserString = userString.replace("'","''");
String insertTableSQL = "INSERT INTO student (column_name) VALUES("
+" '"+data+"' )";