Quantcast
Viewing all articles
Browse latest Browse all 1957

InnoDB -Can't call commit when autocommit=true (2 replies)

Hi,

In Inno DB , I got following exception
Can't call commit when autocommit=true

Can you please explain why this exception happens. I am using MySQL 5.1.48 GA version on windows 32bit - with default config (OOB).


Table DESC:
CREATE TABLE `animal` (
`id` int(10) DEFAULT NULL,
`name` char(40) DEFAULT NULL,
`category` char(40) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


Prog:

import java.sql.*;

public class MySQLClient
{
public static void main (String[] args)
{
Connection MYSQLconn = null;
MySQLClient fs = new MySQLClient();
try
{
String userName = "user";
String password = "password";
java.util.Properties info = new java.util.Properties();
info.put("user", userName);
info.put("password", password);


String url_mysql = "jdbc:mysql://localhost:3306/test";
Driver DBDriver = (Driver)Class.forName ("com.mysql.jdbc.Driver").newInstance ();

//info.setProperty("relaxAutoCommit", "true");
MYSQLconn = DBDriver.connect(url_mysql, info);
System.out.println ("Database connection established");
MYSQLconn.setAutoCommit(true);
fs.selectTable(MYSQLconn);



}
catch (Exception e)
{
System.err.println ("Cannot connect to database server" + e.getMessage());
}
finally
{
if (MYSQLconn != null)
{
try
{
MYSQLconn.close ();
System.out.println ("Database connection terminated");
}
catch (Exception e) { /* ignore close errors */ }
}
}
}



void selectTable(Connection conn) throws Exception
{
Statement s = conn.createStatement ();
s.executeQuery ("SELECT id, name, category FROM animal");
ResultSet rs = s.getResultSet ();
int count = 0;
while (rs.next ())
{
int idVal = rs.getInt ("id");
String nameVal = rs.getString ("name");
String catVal = rs.getString ("category");
System.out.println (
"id = " + idVal
+ ", name = " + nameVal
+ ", category = " + catVal);
++count;
}
conn.commit();
rs.close ();
s.close ();
System.out.println (count + " rows were retrieved");

}
}

Viewing all articles
Browse latest Browse all 1957

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>