SQL Exception

Hi ,

I am using MySql as database for my application. But some times i am getting the following exception frequently.

Here is the excpetionMessage

java.sql.SQLException: Deadlock found when trying to get lock; Try restarting transaction message from server:"Lock wait timeout exceeded; try restarting transaction"

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2001)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1168)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1279)

at com.mysql.jdbc.Connection.execSQL(Connection.java:2281)

at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1825)

at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1667)

Can you guys tell me why this exception is comming frequently.

Here is my code

protectedvoid updateRuleDB(Connection dbcon, Rule rule)

throws SQLException

{

System.out.println("Rule in rule.getxrule"+rule.getXRule());

PreparedStatement ps = dbcon.prepareStatement(Query.MODIFY_RULE_QUERY);

// NAME

ps.setString(1, rule.getName());

// PRIORITY

ps.setInt(2, rule.getPriority());

// STATUS

ps.setString(3, rule.getStatus());

// TODO Convert this into a method to allow future CLOB datatype

// EXPRESSION

ps.setString(4, rule.getExpression());

//Xrule

ps.setString(5, rule.getXRule());

// RULESET_ID

ps.setString(6, rule.getRuleSetId());

// ID

ps.setString(7, rule.getId());

// Run Query

ps.executeUpdate();

// Close 'ps'

ps.close();

regards,

Krishna.

[2179 byte] By [Rampa] at [2007-11-26 18:31:10]
# 1

You have two queries trying to access the same data at the same time - each is waiting for the other to finish so the code deadlocks.

Is hard to tell you exactly what you are doing wrong without seeing your SQL, I'd double check what queries you are running and double check if these cause any other code to fire in triggers etc.

iklestevea at 2007-7-9 6:05:19 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...