I have a sqlite database which contains strings. I am reading those strings from my javafx interface. Everything is working smoothly, however my problem is when I am trying to read strings with apostrophe. My code for reading the strings is the following:
String sql = "select * from Questions where Subject = ? and Grade = ? and Level = ? and questionId = ?";
PreparedStatement pst = gui.connectionQuestions.prepareStatement(sql);
pst.setString(1,gui.textSubjectQTest);
pst.setString(2,gui.showGradeLabel.getText());
pst.setString(3,gui.showCurrentLevelLabel.getText())
pst.setString(4,list.get(counter));
ResultSet rs = pst.executeQuery();
if(rs.next())
{
String temp = rs.getString("Question");
gui.question.setText(temp);
...
sql = "Update Questions set Used ='"+1+"' where Question = '"+gui.question.getText().replaceAll("'", "/'")+"'";
pst = gui.connectionQuestions.prepareStatement(sql);
pst.execute();
In the above code I peform a query to return the question string and add it to a label gui.question. However due to the apostrophe I am receiving the following error (I got the error due to the last line):
[SQLITE_ERROR] SQL error or missing database (near "(": syntax error)
I tried to follow the solution from here, however my prob still remains. How can I solve the thing with the apostrophe?
EDIT: I tried to escape character using double apostrophe. This approach is working but it changes my string to double apostrophe, which is not useful.