SQLITE database Manipulating error with java (IDE:Netbeans) -
i facing problem sqlite database in java ide netbeans.
i have 4 tables in database , 3 tables of them working last 1 table not working! suppose when want insert data in jtable
, database shows values in jtable
but inserts , not insert values database!
below action performed on button through data inserted jtable , database!
private void jbutton17actionperformed(java.awt.event.actionevent evt) { preparedstatement pst = null; connection conn = null; try { string sql = "insert month (no,description,sale,expense,total) values (?,?,?,?,?)"; pst = conn.preparestatement(sql); pst.setstring(1, txt_srm.gettext()); pst.setstring(2, txt_datem.gettext()); pst.setstring(3, txt_tsalem.gettext()); pst.setstring(4, txt_texpm.gettext()); pst.setstring(5, txt_subtm.gettext()); pst.execute(); joptionpane.showmessagedialog(null, "saved!"); } catch (exception e) { joptionpane.showmessagedialog(null, e); } }
you should connect database in first statement. i.e.
con = (yourdb/urdbconnectingclassname) try { string sql = "insert month (no,description,sale,expense,total) values (?,?,?,?,?)"; pst = conn.preparestatement(sql); pst.setstring(1, txt_srm.gettext()); pst.setstring(2, txt_datem.gettext()); pst.setstring(3, txt_tsalem.gettext()); pst.setstring(4, txt_texpm.gettext()); pst.setstring(5, txt_subtm.gettext()); pst.execute(); joptionpane.showmessagedialog(null, "saved!"); } catch (exception e) { joptionpane.showmessagedialog(null, e); }
and if doing so.. must closing db connection in end of method, i.e.
}catch(exception e){ joptionpane.showmessagedialog(null, e); }finally{ try{ rs.close(); //where rs = resultstatement pst.close(); }catch(exception e){ joptionpane.showmessagedialog(null, e); } }
if u dont close connection , connecting in method.. might error of database lock! error..
hope you!
Comments
Post a Comment