participate


Java Database Connectivity (JDBC) - Cloned connection
<<   Back to Forum  |   Give us Feedback
This topic has 25 replies on 2 pages.    1 | 2 | Next »
mortoza
Posts:160
Registered: 3/10/00
Cloned connection   
Oct 28, 2001 4:24 AM

 
Hi
I am developing a Database application. If I use transaction mode (i.e. con.setAutoCommit(false)) then exception occured as follows:

Can't start a cloned connection while in a manual transaction mode

But when I swtich off the transaction mode then it works just fine, but I want to use the transaction mode.

Anyone can help me why it is happening and how to overcome?

thanks in advance
 
bastibubu
Posts:7
Registered: 6/19/01
Re: Cloned connection   
Nov 21, 2001 9:30 AM (reply 1 of 25)  (In reply to original post )

 
i have the same problem :))) i just cannot understand why cannot jdbc driver create several connections when using transactions. or should we use connection pooling? i thought jdbc driver is automatically creating connections on demand, and connection pool just saves new connection creation time

any ideas would be of great appreciation

bastibubu
 
HK_Developer
Posts:1,249
Registered: 1/17/01
Re: Cloned connection   
Nov 22, 2001 12:38 AM (reply 2 of 25)  (In reply to #1 )

 
Sorry, haven't understood yet:
What do you do?

Do you really clone a connection? That would be no good thing at all. A Connection object represents a physical connection to the DBMS; a cloned Connection object would use the same physical connection.

Or do you just get an exception by calling con.setAutoCommit( false ) ?
Then I'd suspect you are in an transaction already and try to switch the transaction mode.
That sounds strange, but notice: even if you are first in AutoCommit( true ) mode, while you are going through a queried ResultSet, you are inside a transaction. The AutoCommit mode will close this transaction automatically as soon as the query is "completed", by
- closing the ResultSet
- closing the Statement or
- reaching the last row of the ResultSet.

If this is your situation, then I'd try to call con.setAutoCommit( false ) directly after opening the connection.

Please - both of you - report your further experiences!
It's really interesting - for me and maybe for others, too.
 
mortoza
Posts:160
Registered: 3/10/00
Re: Cloned connection   
Nov 24, 2001 8:55 PM (reply 3 of 25)  (In reply to #2 )

 
Hi
Thanks for your attention.
I am creating a single connection as soon as the user access the Application and the same connection is being passed to different Swing GUI as parameter where the connection object is used to do all these JDBC job.

It was do fine using other Drivers but while I started using Microsofts JDBC Driver for SQL Server 2000 I have been experiencing this problem.

Now I explain about my implementation.
Before I start retrieving /saving records in table(s) I wrote, connection.setAutoCommit(false) and after all transactions is complete and resultSet and Statement is closed, I passed connection.setAutoCommit(true).
In this case the exception occured as I explained (cloned connection).

But If I close the transaction mode, it works just fine, no exceptions and updates the database.

Ho you have any idea
 
HK_Developer
Posts:1,249
Registered: 1/17/01
Re: Cloned connection   
Nov 26, 2001 3:37 AM (reply 4 of 25)  (In reply to #3 )

 
Before connection.setAutoCommit(true),
have you done connection.commit() or connection.rollback() ?
 
mortoza
Posts:160
Registered: 3/10/00
Re: Cloned connection   
Nov 26, 2001 8:40 PM (reply 5 of 25)  (In reply to #4 )

 
Hi
I have done like this-

try{
connection.setAutoCommit(false);
Statement stmt=connection.createStatement();
........


connection.commit();
connection.setAutoCommit(true);

}catch(SQLException ex){
ex.printStackTrace();
.....
...
connection.rollback();
}
}
 
HK_Developer
Posts:1,249
Registered: 1/17/01
Re: Cloned connection   
Nov 27, 2001 1:08 AM (reply 6 of 25)  (In reply to #5 )

 
Haven't tested this out, but I think it's a risk in general to switch transaction mode on and off.

So I'd close the statement before commit even, to be sure that no rest of the transaction "survives".

After switching the AutoCommit, create a new statement.

Could you try this and report again?
What's the behaviour, which exceptions rise?
 
HK_Developer
Posts:1,249
Registered: 1/17/01
Re: Cloned connection   
Nov 27, 2001 1:08 AM (reply 7 of 25)  (In reply to #5 )

 
Haven't tested this out, but I think it's a risk in general to switch transaction mode on and off.

So I'd close the statement before commit even, to be sure that no rest of the transaction "survives".

After switching the AutoCommit, create a new statement.

Could you try this and report again?
What's the behaviour, which exceptions rise?
 
mortoza
Posts:160
Registered: 3/10/00
Re: Cloned connection   
Nov 27, 2001 1:37 AM (reply 8 of 25)  (In reply to #7 )

 
Hi
I closed the statement before doing the Commit statement. Moreover, I used the same statement to execute several sql to handle data in different, Any suggestions?
 
bastibubu
Posts:7
Registered: 6/19/01
Re: Cloned connection   
Nov 28, 2001 3:09 AM (reply 9 of 25)  (In reply to #8 )

 
i am using tomcat as a container. i think it should automatically create new connection instance, instead of trying to clone existing one. i am creating transactions the same way as u have written here mortoza.

strange is that i thought this was a mssql driver problem. but it appears that it behaves the same way with other drivers too, like JTurbo, or odbc bridge. error messages ar different, but they comply somehow to each other. JTurbo says that Socket is already in use. i thought may be my MSSQL server doesnt allow somehow simultanous connections, but after testing with test application appears that it do can.

so i am confused now :)) where is the problem. what code tries to clone connection instead of creating a new one.

P.S. if i switch transaction mode off, then everything is ok :))
 
HK_Developer
Posts:1,249
Registered: 1/17/01
Re: Cloned connection   
Nov 28, 2001 3:59 AM (reply 10 of 25)  (In reply to #9 )

 
bastibubu,
you seem to be not able to use transaction at all in your environment.
That looks bad. Sorry, can't help.

mortoza,
if I understood right, you get that exception only if you switch the AutoCommit mode.
Could you as workaround stay in AutoCommit( false ) mode? You would have to do the commits explicitely.

Is that possible for you? Or do other problems arise then?
 
mortoza
Posts:160
Registered: 3/10/00
Re: Cloned connection   
Nov 30, 2001 7:56 PM (reply 11 of 25)  (In reply to #10 )

 
Dear Hartmut
You are right. When I set AutoCommit(false) then this problem arises. More surprising thing is sometiomes it works for once. I need to put off the autoCommit mode off in order to ensure data integrety in my database application.

Any help?
 
sonis
Posts:1
Registered: 4/14/98
Re: Cloned connection   
Jan 11, 2002 6:13 AM (reply 12 of 25)  (In reply to #11 )

 
Hi,

You need to use the property 'SelectMethod' for the driver in the URL and set it to 'cursor'

So your driver url should be like :

"jdbc:microsoft:sqlserver://dbmachine:1433;SelectMethod=cursor"



Sandeep Soni.
 
flare2
Posts:3
Registered: 10/28/97
Re: Cloned connection   
Feb 26, 2002 1:31 AM (reply 13 of 25)  (In reply to #12 )

 
It works ...thanks :)
 
kevin-merit
Posts:2
Registered: 1/31/03
Re: Cloned connection   
Feb 11, 2003 7:32 AM (reply 14 of 25)  (In reply to #12 )

 
nice one. fixed my stored procedure by callable statement error as well
(same error message, same cause, i suspect)

kevin.
 
This topic has 25 replies on 2 pages.    1 | 2 | Next »
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 64
  • Guests : 135

About Sun forums
  • Sun Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Sun Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums