java - Data writing error -


i'm inserting data mysql database. unknown reason data not being inserted table. worked fine sqlite. here code:

try {              class.forname("com.mysql.jdbc.driver");                connection conn = drivermanager.getconnection(url, username, password);                string query1 = "insert project (uniqueid,name,address,startingdate,estcompletion,engname) values(?,?,?,?,?,?)";             string query2 = "insert engineerdata (uniqueid,name,password) values(?,?,?)";             string query3 = "insert " +tablename +" (uniqueid,category,item,estimatedquantity,unit,unitprice,totalprice,totalspent) values(?,?,?,?,?,?,?,?)";             string query4 = "insert projectimages (uniqueid, path) values(?,?)";              preparedstatement pst1=  conn.preparestatement(query1);             preparedstatement pst2 = conn.preparestatement(query2);             preparedstatement pst3 = conn.preparestatement(query3);             preparedstatement pst4 = conn.preparestatement(query4);              pst1.setint(1, uniqueid);             pst1.setstring(2, projectname.gettext());             pst1.setstring(3, address.gettext());             pst1.setstring(4, day1.gettext()+"/"+month1.gettext()+"/"+year1.gettext());             pst1.setstring(5, day2.gettext()+"/"+month2.gettext()+"/"+year2.gettext());             pst1.setstring(6, engineername.gettext());              pst2.setint(1, uniqueid);             pst2.setstring(2, engineername.gettext());             pst2.setstring(3, engineerpassword.gettext());              try{             (int j = 0; j < table.getrowcount(); j++ ){                  pst3.setint(1, uniqueid);                 pst3.setstring(2, table.getvalueat(j, 0).tostring());                 pst3.setstring(3, table.getvalueat(j, 1).tostring());                 pst3.setstring(4, table.getvalueat(j, 2).tostring());                 pst3.setstring(5, table.getvalueat(j, 3).tostring());                 pst3.setstring(6, table.getvalueat(j, 4).tostring());                 pst3.setstring(7, table.getvalueat(j, 5).tostring());                  pst3.setdouble(8, 0.0);                 pst3.execute();              }}catch(exception e3){                 /*joptionpane.showmessagedialog(null, e3);                  *                   */             }              pst4.setint(1, uniqueid);             pst4.setstring(2, null);              pst1.execute();             pst2.execute();             pst4.execute();              system.out.println(pst1.tostring());             system.out.println(pst2.tostring());              pst1.close();             pst2.close();             pst3.close();             pst4.close();                conn.close();                }  

you should leave out auto generated column "uniqueid" , rewrite code. ex.

string query4 = "insert projectimages (path) values(?)"; 

another approach - passing null value auto generated column. ex.

string query4 = "insert projectimages (uniqueid, path) values(null,?)"; 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -