[英]Lock wait timeout exceeded- insert using a singleton db manager
在我的Java Web应用程序中,我使用一组Web服务来查询db和jdbc。
使用getter Web服务(选择)时,它可以正常工作,但是当我使用帖子(插入)时,出现此错误:
Lock wait timeout exceeded; try restarting transaction
为了管理数据库,我正在使用此类
...
public final class MysqlConnect {
public Connection conn;
private Statement statement;
public static MysqlConnect db;
private MysqlConnect() {
...
try {
Class.forName(driver).newInstance();
this.conn = (Connection)DriverManager.getConnection(url+dbName,userName,password);
}
catch (Exception sqle) {
sqle.printStackTrace();
}
}
public static synchronized MysqlConnect getDbCon() {
if ( db == null ) {
db = new MysqlConnect();
}
return db;
}
public ResultSet query(String query) throws SQLException{
statement = db.conn.createStatement();
ResultSet res = statement.executeQuery(query);
ResultSetMetaData rsmd = res.getMetaData();
int columnsNumber = rsmd.getColumnCount();
while(res.next()) {
for (int i = 1; i <= columnsNumber; i++) {
if (i > 1) System.out.print(", ");
String columnValue = res.getString(i);
System.out.print(columnValue + " ");
}
System.out.println("");
}
return res;
}
...
public int insert(String insertQuery) throws SQLException {
statement = db.conn.createStatement();
int result = statement.executeUpdate(insertQuery);
return result;
}
}
这是我的WS
@POST
@Path("/postMembership")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public Response postMembership(String MembershipRequest) throws JsonParseException, JsonMappingException, IOException, NamingException{
try {
MysqlConnect.getDbCon().insert("INSERT INTO redmine.members (id, user_id, project_id, mail_notification) VALUES (301, 99, 99, 0)");
} catch(Exception ex) {
System.out.println("Exception getMessage: " + ex.getMessage());
}
return Response.status(200).entity("postMembership is called").build();
}
我正在本地使用此数据库,所以我是唯一使用它的人,
相同的事务适用于mysqlworkbench。
如何摆脱它?
这里有一些建议:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.