| hnabhijith@gmail.com 2007-11-30, 1:26 pm |
| Hi,<br />
<br />
Actually I have been facing the same problem. The connection is closed as soon it is returned. <br />
<br />
I have tried in two ways just to see if I get it right.<br />
<br />
1. Method1<br />
==========<br />
public static Connection getBillingConnection() throws SQLException {<br />
Connection conn = null;<br />
try{<br />
ApplicationContext context = new ClassPathXmlApplicationContext("com/lifetree/ip/dao-spring.xml");<br />
DataSource dataSource = (DataSource) context.getBean("billingDataSource");<br />
<br />
System.out.println("Inside getBillingConnection()::before creating SQLconnection");<br />
Connection sqlConnection = dataSource.getConnection();<br />
if(sqlConnection.isClosed()){<br />
System.out.println("Inside getBillingConnection()::sqlConnection closed");<br />
}else{<br />
System.out.println("Inside getBillingConnection()::sqlConnection is open");<br />
}<br />
System.out.println("Inside getBillingConnection()::after getting SQLConnection");<br />
WSJdbcConnection wsConnection = (WSJdbcConnection) sqlConnection;<br />
System.out.println("Inside getBillingConnection()::after getting wsConnection");<br />
conn = (Connection) WSJdbcUtil.getNativeConnection(wsConnection); <br />
// conn = (Connection) WSJdbcUtil. getNativeConnection((WSJdbcConnection)da
taSource.getConnection()); <br />
System.out.println("Inside getBillingConnection()::after creating the connection");<br />
if(conn!=null){<br />
System.out.println("Inside getBillingConnection()::Connection is not null");<br />
}else{<br />
System.out.println("Inside getBillingConnection()::Connection is null");<br />
}<br />
if(conn.isClosed()){<br />
System.out.println("Inside getBillingConnection()::Connection closed");<br />
}else{<br />
System.out.println("Inside getBillingConnection()::Connection is open");<br />
}<br />
<br />
billingDBCount = billingDBCount++;<br />
System.out.println("No of connections open = "+billingDBCount);<br />
}catch(Exception e){<br />
System.out.println("Exception in getBillingConnection() = "+e.getMessage());<br />
e.printStackTrace();<br />
}<br />
return conn;<br />
}<br />
========================================
===============================<br />
Method 2<br />
==========<br />
public static Connection getBillingConnection() throws SQLException {<br />
java.sql.Connection conn = null;<br />
try{<br />
ApplicationContext context = new ClassPathXmlApplicationContext("com/lifetree/ip/dao-spring.xml");<br />
System.out.println("getBillingConnection()::got the context");<br />
javax.sql.DataSource ds = (javax.sql.DataSource) context.getBean("billingDataSource");<br />
System.out.println("getBillingConnection()::got the Datasource");<br />
com.ibm.ws.rsadapter.jdbc.WSJdbcConnection nativeCon1 = (com.ibm.ws.rsadapter.jdbc.WSJdbcConnection) ds.getConnection ();<br />
System.out.println("getBillingConnection()::got the native connection");<br />
conn = (java.sql.Connection ) WSJdbcUtil.getNativeConnection(nativeCon1);<br />
System.out.println("getBillingConnection()::got the sqlconnection");<br />
if(conn!=null){<br />
System.out.println("Inside getBillingConnection()::Connection is not null");<br />
}else{<br />
System.out.println("Inside getBillingConnection()::Connection is null");<br />
}<br />
if(conn.isClosed()){<br />
System.out.println("Inside getBillingConnection()::Connection closed");<br />
}else{<br />
System.out.println("Inside getBillingConnection()::Connection is open");<br />
}<br />
}catch(SQLException sqle){<br />
<br />
}<br />
return conn;<br />
}<br />
=======================================<br />
<br />
Any help? I have tried almost everything <img class="jive-emoticon" border="0" src="images/emoticons/sad.gif" alt=" "><br />
<br />
Can anyone gimme the code to get this working?<br />
<br />
Thanks in advance<br />
Abhijith
|