Updating a sqlite database from Java -


i trying update sqlite db javafx. perform following query database in order update it:

try    {   int savespeed = gui.savespeedint - gui.savespeedtimer;   string query2;   if(gui.textanswerq.equals(gui.saveanswer.gettext()) || gui.textanswertofq.equals(gui.saveanswer.gettext()) || gui.sanswertextfield.gettext().equals(gui.saveanswer.gettext())){      string answer = "1";     query2 = "update studentsquestions set time = '"+savespeed+"' set answer = '"+answer+"' username = '"+gui.saveuser.gettext()+"' , question = '"+gui.question.gettext()+"'";                    }   else{     string answer = "0";     query2 = "update studentsquestions set time = '"+savespeed+"' set answer = '"+answer+"' username = '"+gui.saveuser.gettext()+"' , question = '"+gui.question.gettext()+"'";   }    preparedstatement pst2 = gui.connectionusers.preparestatement(query2);   pst2.execute();   pst2.close();  } 

when performed updating time answer field seems empty. doing wrong here? aswer field studentsquestions table type integer , schema "answer integer".

edit: indeed figure out cant put 2 sets inside same query. not aware how can seperate query prepared statement. help?

creating prepared statements way go. fix code such (the main error not having comma , using set twice in sql statement):

try    {   int savespeed = gui.savespeedint - gui.savespeedtimer;   string query2;   int answer = 1;   if(gui.textanswerq.equals(gui.saveanswer.gettext()) || gui.textanswertofq.equals(gui.saveanswer.gettext()) || gui.sanswertextfield.gettext().equals(gui.saveanswer.gettext())){     answer = 1;   }   else{     answer = 0;   }   query2 = "update studentsquestions set time = ?, answer = ? username = ? , question = ?";   preparedstatement pst2 = gui.connectionusers.preparestatement(query2);   pst2.setint(1, savespeed);   pst2.setint(2, answer);   pst2.setstring(3, gui.saveuser.gettext());   pst2.setstring(4, gui.question.gettext());   pst2.execute();   pst2.close();  } 

for more info see this: using sqlite prepared statements basics


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -