0
在我的Java Web應用程序中,我使用一組Web服務來查詢數據庫和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();
}
我使用該DB本地所以我在使用它的只有一個,
同一事務與mysqlworkbench一起使用。
如何擺脫它?
這可能與此問題有關[避免鎖等待超時](http://stackoverflow.com/questions/13966467/how-to-avoid-lock-wait-timeout-exceeded-exception) – caburse