[Microsoft] [sqlserver JDBC driver] Can't start a cloned connection while in manual transaction

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.