Database connection Problem ?

Hi,

In my application I am calling the database connection to retrive and store the data from DB2.

But sometimes randomly I am getting the exception like below.

[IBM][JDBC Driver] CLI0601E Invalid statement handle or statement is closed. SQLSTATE=S1000

My connection class is singleton. when ever I need the database connection I am calling the getConnection() from Singleton class.

So can anyone tell what is the problem?

Can i solve this problem using connection pooling? if yes, can i use the connection pooling for standalone applications.

Thanks

[599 byte] By [nim_ramesha] at [2007-11-26 19:28:45]
# 1
Sounds like you might be trying to use a statement after you close it? Have you looked into that?
zadoka at 2007-7-9 21:56:26 > top of Java-index,Java Essentials,Java Programming...
# 2

Could it be your connection is idle for long enough to be closed by the DBMS?

>Can i solve this problem using connection pooling?

>if yes, can i use the connection pooling for standalone applications.

First I would get to the bottom of the error as it stands.

The main advantage to using connection pooling in a

standalone application is if it's multithreading and is

hitting the database from multiple thread concurrently.

DrLaszloJamfa at 2007-7-9 21:56:26 > top of Java-index,Java Essentials,Java Programming...
# 3

I am trying to solve my problem without connection pooling.

But I checked in my code there is no statement close call.

my application is not waiting too long also.

--

Yes, I am also using the threading in my application.

So can you please tell me how can i use the connection pooling. How can i implement ? can you send some examples and tutorials, if anyone have.. just for idea..

thanks

nim_ramesha at 2007-7-9 21:56:26 > top of Java-index,Java Essentials,Java Programming...
# 4

> I am trying to solve my problem without connection

> pooling.

> But I checked in my code there is no statement close

> call.

You don't close statements anywhere? You will need to if you go the pooling route.

>

> my application is not waiting too long also.

> --

> Yes, I am also using the threading in my

> application.

>

Are the threads sharing the same connection?

>So can you please tell me how can i use the

>connection pooling. How can i implement ? can

>you send some examples and tutorials, if anyone

> have.. just for idea..

Like it has been suggested it is a better idea to find the root problem then cover up the symptoms.

zadoka at 2007-7-9 21:56:26 > top of Java-index,Java Essentials,Java Programming...
# 5
Yes, threads are sharing the same connection.and My connection object is singleton and thread safe.
nim_ramesha at 2007-7-9 21:56:26 > top of Java-index,Java Essentials,Java Programming...
# 6
Can anyone know How to implement connection pooling for the standalone applicaiton in java?I am using 2 databases, do I need the 2 connection pools or One?
nim_ramesha at 2007-7-9 21:56:26 > top of Java-index,Java Essentials,Java Programming...
# 7

1. You seem to be jumping on the connection pooling bandwagon without

much thought. But... in any case you should not code your own pool.

There are lots of good implementations already out there, like C3P0:

http://sourceforge.net/projects/c3p0

2. Multiple threads sharing a connection is a bad, bad thing. How

will you keep their transactions straight? Suppose one thread wants

to commit while another, concurrently, wants to roll back. Uh oh.

DrLaszloJamfa at 2007-7-9 21:56:26 > top of Java-index,Java Essentials,Java Programming...
# 8

HI thanks for the information,

I run my application without threads but still gettting the same Exception

[IBM][JDBC Driver] CLI0601E Invalid statement handle or statement is closed. SQLSTATE=S1000

I think some how my application is not creating the statement after certain time.

stmt = DB2Conn.createStatement();

here I am getting the exception after some time...

-

Your write, I don't have much knowledge of connection pooling so i am trying to solve the problem without pooling.

nim_ramesha at 2007-7-9 21:56:27 > top of Java-index,Java Essentials,Java Programming...
# 9
Hi,I print out DB2Connection. Some time the connectionHandle is 0 of DB2Connection.DB2Connection{connectionHandle = 0When the connection hable will become 0?
nim_ramesha at 2007-7-9 21:56:27 > top of Java-index,Java Essentials,Java Programming...
# 10
Hi all, Can anyone know the exact problem?why its getting the exception randomly[IBM][JDBC Driver] CLI0601E Invalid statement handle or statement is closed. SQLSTATE=S1000Thanks
nim_ramesha at 2007-7-9 21:56:27 > top of Java-index,Java Essentials,Java Programming...
# 11
I use the same technique also multiple threads and everything works fine for me. Not closing your connections seems like a bad idea to me and may be even the cause of your problem. Do you get the error on a createStatement?
pholthuizena at 2007-7-9 21:56:27 > top of Java-index,Java Essentials,Java Programming...