0
我使用了MyBatis,我想更新数据库中的数据,插入查询可以正常工作,但我在更新时出现了这个错误。更新数据库时出错:超出锁定等待超时
Error updating database. Cause: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
SqlMapConfig.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<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="***"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="config/UserMapper.xml"/>
</mappers>
</configuration>
UserMapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="dao.UserDao">
<update id="update" parameterType="User">
update user set adress_u = #{adress_u} where id_u = #{id_u}
</update>
</mapper>
Test.java
String adress_u = (String) request.getAttribute("adress_u");
int id_u = (Integer) request.getAttribute("id_u");
SqlSession session = MyBatisSqlSessionFactory.getSession();
User u = new User();
u.setId_u(id_u);
u.setAdress_u(adress_u);
session.update("dao.UserDao.update", u);
session.commit();
session.close();
感谢。
谢谢非常 –