What I thought was a minor problem has become a bear: apostrophe in
sql statemements. I read that the thing to do is use a
preparedStatement. Here's my code:
String query = "INSERT INTO names (first, last, idNum) VALUES
(?, ?, ?) ";
System.out.println(query);
try {
PreparedStatement pSt = cn.prepareStatement(query);
pSt.setString(1,first);
pSt.setString(2,last);
pSt.setInt(3,1);
}
pSt.executeUpdate(query);
pSt.close();
Everything works fine until I input a name with an apostrophe, then
it throws an SQL Syntax error. I've tried many other things
without successful. I'm running sdk 1.4.1, mysql and J/Connector.
Any suggestions would be appreciated.