2 messages in com.mysql.lists.javaProblem with autocommit
FromSent OnAttachments
Miłosz Hulbój05 Oct 2006 05:52 
Eric Herman11 Oct 2006 07:27.java
Subject:Problem with autocommit
From:Miłosz Hulbój (mhul@gmail.com)
Date:10/05/2006 05:52:18 AM
List:com.mysql.lists.java

Hello, I am observing some non-deterministic behaviour of the autocommit. It seems as if sometimes it doesn't manage to commit the changes - in the example the resulting table is sometimes empty.

Here are the details about the setup: mysql-connector-java-3.1.13 mysql-connector-java-5.0.3 MySQL 4.0.20 under Linux MySQL 4.1.14 under Linux Java 1.4.2_07-b05 (under Linux)

MySQL 4.1.14-nt - under Windows

Here is the code:

========

import java.sql.*;

class example {

public static void main (String[]args) { // following code sometimes returnes 0 even if input table is not empty // disabling the autocommit and issuing manual commit seems to work fine while (true) { try { Class.forName ("org.gjt.mm.mysql.Driver"); } catch (Exception e) { System.out.println ("AAAA"); }

Connection connection = null; Statement statement = null; ResultSet rs = null; try { connection = DriverManager.getConnection ("jdbc:mysql:///test", "", ""); //connection.setAutoCommit(false); statement = connection.createStatement (); statement.execute ("DROP TABLE IF EXISTS ccc"); statement.execute ("CREATE TABLE ccc(a INT(11), b INT(11))"); int n = statement.executeUpdate("INSERT INTO ccc SELECT * FROM cccc"); // The line below seems to work without problems // int n = statement.executeUpdate ("INSERT INTO ccc VALUES(1,2)"); statement.close (); //connection.commit(); connection.close ();

connection = DriverManager.getConnection ("jdbc:mysql:///test", "", ""); statement = connection.createStatement (); rs = statement.executeQuery ("select count(*) from ccc"); rs.next (); System.out.println (rs.getInt (1) + " n=" + n); rs.close (); statement.close (); connection.close (); } catch (SQLException ex) { System.out.println ("SQLException: " + ex.getMessage ()); System.out.println ("SQLState: " + ex.getSQLState ()); System.out.println ("VendorError: " + ex.getErrorCode ()); } } } }

========

Table cccc may contain any number of rows. Currently I am trying with just one.

Did anyone had similar problem or know a solution to this?

Regards, Milosz Hulboj