Problem : The data with apostrophe is not getting saved in MySQL database properly.
In my case I was trying to save <John's Car> in the database. But was getting error on executing the update statement.
Solution : I read some solution like using methods to escape apostrophe. But in the end, as I was coding in Java, what I found the best approach is using PreparedStatement.
When you set data like following, escaping is handled implicitly by Java.
Did it work for you?
In my case I was trying to save <John's Car> in the database. But was getting error on executing the update statement.
Java MySQL JDBC |
Solution : I read some solution like using methods to escape apostrophe. But in the end, as I was coding in Java, what I found the best approach is using PreparedStatement.
When you set data like following, escaping is handled implicitly by Java.
PreparedStatement pstmt = con.prepareStatement("UPDATE CUSTOM_TABLE SET CUSTOM_COLUMN = ?");
pstmt.setString(1, "John's Car");
Did it work for you?
0 nhận xét:
Đăng nhận xét