Re: setting lock table on mysql via java mysql-connector-java-3.1.7-bin.jar



Ok, I'll answer my own question, in case anyone else is interested.

two fixes to above will allow it work fine. The close statements are
put into the finally block, as this gets executed whether or not there
is an exception.

enjoy............

Statement stmt = null;
try{
stmt = connection.createStatement();
stmt.execute("LOCK TABLES mytablename WRITE");
int rowNumber = stmt.executeUpdate(sql);
}
catch(SQLException ex) {
System.out.println("SQL Exception caught + ex.getMessage() );
throw new SQLException(ex.getMessage() ,ex.getSQLState() );
}
finally{
if(stmt != null){
stmt.execute("UNLOCK TABLES");
stmt.close();
}
}

.