title: Lock wait timeout exceeded; try restarting transaction using JDBC
body: <p>I have a MySQL table named <code>Student</code> with two columns <code>Student_id</code> and <code>name</code>.</p>
  
  <p>I am firing two queries using two connection objects, and it is giving me an Exception:</p>
  
  <pre><code>Exception in thread "main" java.sql.SQLException: Lock wait timeout 
  exceeded; try restarting transaction
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4074)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4006)
      at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2468)
      at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2629)
      at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2713)
      at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2663)
      at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:888)
      at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:730)
      at jdbc.ConnectUsingJdbc.main(ConnectUsingJdbc.java:19)
  </code></pre>
  
  <p>Here is the code that produces the error:</p>
  
  <pre><code>package jdbc;
  
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.SQLException;
  import java.sql.Statement;
  
  public class ConnectUsingJdbc {
  
      public static void main(String[] args) 
          throws ClassNotFoundException, SQLException{
  
          Class.forName("com.mysql.jdbc.Driver");
          Connection connection = DriverManager.getConnection(
              "jdbc:mysql://localhost:3306/test","root","root");
          Connection connection1 = DriverManager.getConnection(
              "jdbc:mysql://localhost:3306/test","root","root");
          connection.setAutoCommit(false);
          connection1.setAutoCommit(false);
          Statement statement = connection.createStatement();
          statement.execute("insert into student values (3,'kamal')");
          Statement statement1 = connection1.createStatement();
          statement1.execute("delete from student where student_id = 3");
          connection.commit();
          connection1.commit();
      }
  }
  </code></pre>
  
  <p>I am trying to delete the row using the <code>connection1</code> object that I inserted using the other <code>connection</code> object.</p>
  
  <p>Why am I getting this error?</p>