• 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

StaleConnectionException

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i 'm using WAS5.0 .
When I execute the following jsp i get
com.ibm.websphere.ce.cm.StaleConnectionException: Connection is closed
I'm using a WAS 4 transactional datasource connected to oracle
DataSource properties :
"mydbpool" DataSource Properties [oracle.jdbc.xa.client.OracleXADataSource]: {URL=jdbc racle:thin:@10.87.10.32:1521 bdev9ii;user=XYZ;password=XXXXXXXX;description=mydbpool;databaseName=obdev9ii;} Connection Pool Properties: minConnectionPoolSize = 1 maxConnectionPoolSize = 30 connTimeout = 1000 idleTimeout = 2000 orphanTimeout = 1800 maxStatementCacheSize = 100 autoConnectionCleanupDisabled= true errorMap = null informixLockModeWait = 0 oracleStmtCacheSize = 0 connectionValidation = false validationSQL = null resetReadOnly = false

JSP:
"& lt;" %@ page import="java.util.*" %>
"& lt;" %@ page import="javax.naming.*" %>
"& lt;" %@ page import="javax.transaction.*" %>
"& lt;" %@ page import="javax.sql.*" %>
"& lt;" %@ page import="java.sql.*" %>
"& lt;" %
DataSource _dataSource = null;
Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
UserTransaction ut = null;
String DATA_SOURCE_STRING = "mydbpool";
Hashtable env = new Hashtable();
try
{
Context initialContext = new InitialContext();
out.println("Got IC ---------->" + initialContext);
_dataSource = (DataSource) initialContext.lookup(DATA_SOURCE_STRING);
out.println("
Got DS ---------->" + _dataSource);
ut = (UserTransaction) initialContext.lookup("java:comp/UserTransaction");
}
catch (NamingException ne)
{
out.println("
Exception caught ---------->");
ne.printStackTrace();
}
int i = 0;

try
{
System.out.println("Staring explicit transaction");
ut.begin();
conn = _dataSource.getConnection();
//conn.setAutoCommit(false);
out.println("
Got conn ---------->" + conn);
try
{
stmt = conn.createStatement();
}catch(com.ibm.websphere.ce.cm.StaleConnectionException _e)
{
out.println("
Exception at create statement : " +_e);
_e.printStackTrace();
out.println("
statement is ---------->" + stmt);
}
out.println("
statement created ---------->" + stmt);
//ut.begin();
rs = stmt.executeQuery("select router_id from router");
//out.println("
Executed Query ---------->" );
/**
while(rs.next())
{
out.println("
Router id : + " + i + rs.getInt(1));
i++;
}
*/
//conn.commit();
System.out.println("Committing explicit transaction");
ut.commit();
out.println("
txn commited ---------->");
}
catch(Exception e)
{
ut.rollback();
out.println("
txn rolled back ---------->");
out.println("
connection is ---------->" + conn);
out.println("
Exception caught here ---------->" + e);
e.printStackTrace();
}
finally
{
try
{
//rs.close();
if (stmt != null)
{
stmt.close();
}
if (conn != null)
{
conn.close();
}
}
catch(Exception e)
{
out.println("
Exception closing resources : " +e);
e.printStackTrace();
}
}
%>
Thanx in Advance
Anil
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Anil
Welcome to the world of do{} while() to handle StaleConnection Exception.
Whether you found a solution not to get this StaleConnectionException or not, you never know when is the next time it might occur. So I will definitely request you to look at any of the Websphere Connection Pooling Document to find out how they handle StateConnectionException by using "retry" parameter to handle the same. You can decide how many times you want to retry getting the connection and do the business logic if you are getting StaleConnectionException.
Reason for getting StateConnectionException are serveral... Check out the document for a detailed explanation on the same.
 
infotainment infotainment
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have ready the reasons for stale connection problem and also implemented the do while things to try again.
But the error does not goes.
The error appears as I 'm using the declarative transaction .If I remove tx.begin() then things work fine , but I need to have the declarative transactions.
Any help really appreciated.
Regards
~Anil
 
infotainment infotainment
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is at the "stmt = conn.createStatement();
Regards
~Anil
 
All of the following truths are shameless lies. But what about this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic