Symptoms
While using the Microsoft SQL Server 2000 driver for JDBC, you may experience the following exception: Java. SQL. sqlexception: [Microsoft] [sqlserver 2000 driver for JDBC] Can't start a cloned connection while in manual transaction mode. cause
This error occurs when you try to execute multiple statements against a SQL Server database with the JDBC driver while in manual transaction mode (autocommit = false) and while using the direct (selectmethod = direct) mode. direct mode is the default mode for the driver. resolution
When you use manual transaction mode, you must setSelectmethodProperty of the driver to cursor, or make sure that you use only one active statement on each connection as specified in the "More Information" section of this article. Steps to reproduce the behavior
Use the following code to reproduce the error:
Note: See the comments in the Code for information on the code changes that are required to resolve the problem. Import java. SQL .*;
Import java. Io .*;
Public class repro {
Public static void main (string ARGs [])
{
Try {
Connection con;
Statement S1 = NULL;
Resultset R1 = NULL;
Statement S2 = NULL;
Resultset r2 = NULL;
Class. forname ("com. Microsoft. JDBC. sqlserver. sqlserverdriver ");
Con = drivermanager. getconnection (
"JDBC: Microsoft: sqlserver: // localhost: 1433; databasename = pubs; selectmethod = direct; user = user; Password = password ");
// Fix 1
// "JDBC: Microsoft: sqlserver: // localhost: 1433; databasename = pubs; selectmethod = cursor; user = user; Password = password ");
Con. setautocommit (false );
Try {
S1 = con. createstatement ();
R1 = s1.executequery ("select * from authors ");
// Fix 2
// R1.close ();
// S1.close ();
S2 = con. createstatement ();
R2 = s2.executequery ("select * from publishers ");
}
Catch (sqlexception ex)
{
System. Out. println (Ex );
}
}
Catch (exception E)
{
E. printstacktrace ();
}
}
}
Http://support.microsoft.com/default.aspx? SCID = KB; en-US; q313181