mak_doni mak_doni - 1 year ago 126
SQL Question

Error updating database:Lock wait timeout exceeded

I used MyBatis, I want to update data in the database, the insert query works but i have this error in the update.

Error updating database. Cause: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-// Config 3.0//EN" "">
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost/test"/>
<property name="username" value="root"/>
<property name="password" value="***"/>
<mapper resource="config/UserMapper.xml"/>


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-// Mapper 3.0//EN" "">
<mapper namespace="dao.UserDao">
<update id="update" parameterType="User">
update user set adress_u = #{adress_u} where id_u = #{id_u}

String adress_u = (String) request.getAttribute("adress_u");
int id_u = (Integer) request.getAttribute("id_u");

SqlSession session = MyBatisSqlSessionFactory.getSession();
User u = new User();

session.update("dao.UserDao.update", u);


Answer Source

You should consider increasing the lock wait timeout value for InnoDB by setting the innodb_lock_wait_timeout, default is 50 sec

mysql> show variables like 'innodb_lock_wait_timeout';

You can set it to higher value and restart mysql :

SET GLOBAL innodb_lock_wait_timeout = 120; 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download