mysql - lock wait time out exceeded in java jdbc transaction -


i created code adding data 3 tables. got error, lock wait time out exceeded. in database, i'm adding values takerslist, q_enrolls , test tables. i'm getting data qbank , question tables. takerlist foreign key stdid. think it's not important here. q_enroll's foreign keys qid(references question table), qbankid(references qbank) , testid(references test).

@override public int add(test e, connection connection) throws sqlexception, classnotfoundexception, remoteexception {     string query = "insert test values(?,?,?,?,?,?,?)";     object[] data = {e.gettestid(), e.gettestname(), e.gettestfrom(), e.gettestto(), e.gettotalquestions(), e.gettestdate(), e.getpassmark()};     try {         connection.setautocommit(false);         int res = dbhandle.setdata(connection, query, data);         if (res > 0) {             list<takerlist> list = e.getlisttakers();             takerlistmanagementmodel takerlistmodel = new takerlistmanagementmodel();             questionenrollmanagementmodel enrollmodel = new questionenrollmanagementmodel();             takerlistmodel.setaddcommonbehavior(true);             enrollmodel.setaddcommonbehavior(true);             list<list<bankquestion>> selqs = null;             string testid = null;             (takerlist tl : list) {                 int restakers = takerlistmodel.performadd(tl);                 if (restakers > 0) {                     selqs = e.getlistqbanks();                     testid = tl.gettestid();                 } else {                     connection.rollback();                     return 0;                 }             }             (list<bankquestion> list1 : selqs) {                 (bankquestion bankquestion : list1) {                     questionenroll enroll = new questionenroll(bankquestion.getqid(), testid, bankquestion.getqbankid());                     int resqlist = enrollmodel.performadd(enroll);                     if (resqlist==0) {                         return 0;                     }                 }             }             connection.commit();             return 1;         } else {              connection.rollback();             return 0;         }     } catch (sqlexception ex) {         connection.rollback();         throw ex;     } {         connection.setautocommit(true);     } } 

you can set lock timeout database explicitly (as updates keep transaction open long). mysql can find detailed instructions here

basically set command in /etc/my.cnf permanently line

[mysqld] innodb_lock_wait_timeout=120 

and restart mysql. if cannot restart mysql @ time, run this:

set global innodb_lock_wait_timeout = 120;  

you set duration of session

set innodb_lock_wait_timeout = 120;  

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -