troubleshooting Question

setAutoCommit problem.. urgent..please help

Avatar of pleasure
pleasure asked on
Java
8 Comments1 Solution295 ViewsLast Modified:
hi experts,
i wish to know how can close a cloned transaction?

just tak a look at my code then you will understand better

//*****************************************
import java.sql.*;
class TestDB
{
  public static void main(String args[])
  {
  Connection conn
  try
  {
    DbManager dbManager = new DbManager();
    String strSql = "Select * From tblReportGroup";
    Statement stmtThis = conn.createStatement();
    //Create a statement to execute query
    ResultSet rsThis = stmtThis.executeQuery(strSql); ;

    while (rsThis.next())
    {
     String rptGrpId = rsThis.getString(1);
     String rptGrpDesc = rsThis.getString(2);

     strSql = " Select * From tblReportAssign Where fldReportGrpID = '" + rptGrpId + "'" +
     " Order By fldSeq";    
     
     Statement stmtThis = conn.createStatement();
    //Create another statement to execute another query

     ResultSet rsThis2 = stmtThis.executeQuery(strSql); ;

     while (rsThis2.next())
     {
       String rptId = rs.getString(3);
     }
   }
  conn.setAutoCommit(false);          
  /*
  when i try to setAutoCommit(false), i get this error
  [Error] - [Microsoft][SQLServer 2000 Driver for JDBC]  Can't start manual transaction mode because there are cloned connections.
I know this is because i have 2 statement is running.. how can close the statement??
*/
 
  //I will do something here...
  conn.setAutoCommit(true);
}
catch(Exception e)
{
  System.out.println("[Error] - " + e.getMessage());
}
}
}
//*****************************************

can someone please explain to me how does transaction work in Java? As i know, when we setAutoCommit(false), we can only have one Statement running..therefore when it really happen that i need to have 2 Statement object running at the same time, what should i do..

please guide..

thanks a lot..:)
ASKER CERTIFIED SOLUTION
Venci75

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros