• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

No operations allowed after statement closed.

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using C3p0 as my JDBC connection pool with MySql.

I get the following exception after I don't hit the server for a while. While other times, it works.

Can you please tell me what may be the root cause of the problem and how can I fix it?

Thank you.




[ August 20, 2008: Message edited by: Scott Selikoff ]
 
author
Posts: 4223
33
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's pretty self-explanatory; somewhere you close a Statement then try to use it again. Check the method "com.mycompany.myapp.FontDB.getMetrics" and see where you might be using a statement that you previously closed.
 
ying lam
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. But I always do this.
So I don't think i can use a statement which is closed.

 
Scott Selikoff
author
Posts: 4223
33
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the exception thrown in the main try block or in the finally? It's possible an error closes the exception early, and the finally is attempting to close an all ready closed exception.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

it seems like I am experiencing a similar problem. Mine however works when there is only one thread accessing the function. However, when multiple threads hit it at the same time, I constantly start receiving the error. I wonder if you could fix the problem?

My function is defined as synchronized, so it is very unlikely that threads interfere to one anothers job. any idea?

 
author & internet detective
Posts: 40188
812
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nemo,
Welcome to JavaRanch!

I recommend not having connection as an instance variable. You could have a local/method variable that gets the connection at the beginning of the method and closes it at the end in a finally block.

It's logically close to what you are doing anyway, since you close the connection each time. Except yours wastes resources since the connection is kept open between queries.
 
Nemo Cavianini
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Jeanne for the reply and thanks for welcoming me

I wonder if it is a good practice to keep on opening and closing the connection as it is often the case the opening connection to the DB imposes extra overhead to the system as it requires a TCP handshake with the mysql server. In our case performance is an issue, so my preference would be to not even bother with opening and closing the connection to the DB, but to simply leave it open.

However, in that case, I face more disruptions when polling from the DB. Do you, or anybody in the forum, know of best practices for allowing access to the DB in multi-threaded environments? It would be a great help if someone could kindly refer me to such a resource.

cheers,
Nemo
 
Jeanne Boyarsky
author & internet detective
Posts: 40188
812
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nemo,
If you use a connection pool like dbcp, the overhead is minimal since the connection isn't closed - merely returned to the pool. Even if you only have one connection in your pool, I recommend this approach for a multi-threaded application. Especially one that has a lot of connections opening and "closing."

Your performance is likely to be better with a pool than your current approach too.
 
Nemo Cavianini
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne,

I am using DBCP already, but my environment is a bit tricky as I am developing everything on top of OSGi.

One problem that I am facing right now is that the connections in the pool for DBCP get timed out after a while of sitting idle. I am using a JDBC implementation of DBCP, I wonder if there is any way to validate the connections in a pool to somehow abandon the obsolete ones?

thanks,
Nemo
 
This cake looks terrible, but it tastes great! Now take a bite out of this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic