I am trying to insert Gandhi's Salt March as the Name in the Name column of my database. I have the following function to detect apostrophes in names and capitalize the starting character:
public static String toTitleCase(String givenString) {
StringBuffer sb = null;
if(givenString.contains("'")){
givenString = givenString.replace("'", "\\'");
System.out.println("Replace: "+givenString);
}
try{
String[] arr = givenString.split("\\s+");
sb = new StringBuffer();
for (int i = 0; i < arr.length; i++) {
sb.append(Character.toUpperCase(arr[i].charAt(0))).append(arr[i].substring(1)).append(" ");
}
}catch(Exception e){
System.out.println(e);
}
System.out.println(sb.toString().trim());
return sb.toString().trim();
}
The first System.out.println() results in the following:
Replace: Gandhi\'s Salt March
In SQLite I get the following exception:
(1) near "s": syntax error
From catch 2android.database.sqlite.SQLiteException: near "s": syntax error (code 1): , while compiling: INSERT INTO Details (BirthDate, Name);
What is going wrong here?
Aucun commentaire:
Enregistrer un commentaire