I get the following exception at times:
com.ibm.db2.jcc.b.gm: [jcc][t4][2030][11211][3.50.152] A communication error occurred during operations on the connection's underlying socket, socket input stream,
or socket output stream. Error location: Reply.fill(). Message: Connection reset. ERRORCODE=-4499, SQLSTATE=08001
The problem is that, the code executes successfully for quite some time and then suddenly I get this exception. However it runs perfrectly when I run the code again.
Could some one please tell me what could be wrong and provide me some pointers to resolve this.
Best Answer
This is a sign of not properly closing/releasing JDBC resources. You need to acquire and close all JDBC resources in the shortest possible scope, i.e. you need to close them in the reversed order in the
finally
block of thetry
block of the very same method block as you've acquired them. E.g.If you don't close them properly as soon as possible, the DB will take it in own hands sooner or later and your application may break sooner or later as you encountered yourself.
To improve connecting performance, make use of a connection pool --you still need to acquire and close them in the same manner as here above though! It's now just the connection pool implementation which under the hoods worries about actually closing the connection or not.