-
1. Re: Is connection close needed?
jonlee Jun 9, 2003 5:23 AM (in response to lee_yuki2000)In general, you should close the statement and the connection in that order. The connection is not truly closed but merely returned to the pool. If you do not "close" the connection it will not return the connection to the pool until the bean dies or the connection times out, whichever comes first. Under the EJB spec, your bean may not be passivated until the container is assured that the transaction is completed.
The max and min pool sizes are supported, they just aren't included in the example template you used. Look at docs/examples/jca/generic-ds.xml to see where these values should go within your own template. -
2. Re: Is connection close needed?
lee_yuki2000 Jun 9, 2003 6:40 AM (in response to lee_yuki2000)Thanks for your reply. I have error if i close the connection. If i do not close the connection everything will be fine. Once i close it, i cannot get the connection.
Do you know why?
[org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener] throwable from unregister connection
java.lang.IllegalStateException: Trying to return an unknown connection1! org.jboss.resource.adapter.jdbc.WrappedConnection@49494e
at org.jboss.resource.connectionmanager.CachedConnectionManager.unregisterConnection(CachedConnectionManager.java:264)
at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener.connectionClosed(TxConnectionManager.java:550) -
3. Re: Is connection close needed?
lee_yuki2000 Jun 9, 2003 7:27 AM (in response to lee_yuki2000)Sometimes i have this error after i have close the connection.
java.sql.SQLException: Connection handle has been closed and is unusable
at org.jboss.resource.adapter.jdbc.WrappedConnection.checkStatus(WrappedConnection.java:800)
at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:218)
at sqlj.runtime.profile.ref.JDBCProfile.prepareCachedStatement(JDBCProfile.java:334)
Do you know why? -
4. Re: Is connection close needed?
jonlee Jun 9, 2003 8:26 AM (in response to lee_yuki2000)Sounds like there is a physical connection problem or there is a problem completing the transaction. Have you tried accessing and using a connection from a stateless session bean? And does this problem occur for a 3.0.x implementation when you explicitly close the connection?
-
5. Re: Is connection close needed?
lee_yuki2000 Jun 9, 2003 11:07 PM (in response to lee_yuki2000)I am using stateless bean and my transaction type is BMP.
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
Do u know what's wrong?
Thank you very much -
6. Re: Is connection close needed?
jonlee Jun 10, 2003 8:46 AM (in response to lee_yuki2000)BMP doesn't really exist in your instance as this term really only applies properly to Entity beans. However, I take your meaning.
Perhaps if you share how you go about obtaining the connection, it might allow folks here to diagnose the issue.
I haven't seen this actual problem before but it smells like the underlying physical connection is perhaps being lost. I would check your Oracle logs for loss of connection.
Does the transaction complete? Does the data get written or read? -
7. Re: Is connection close needed?
lee_yuki2000 Jun 11, 2003 10:06 PM (in response to lee_yuki2000)The reason why i cannot reuse the connection when i have close the connection is because i didn't set the connection = null. I am using the default connection.
I just need to know it is i have to close the connection after every sql statement? Some people say yes and some people say no. So i m a bit confused here.
If i need to close the connection, i need to set the connection = null instead of getting the default connection.
public void activate() throws NamingException, SQLException {
if (dataSource == null) {
try {
dataSource = DataSourceDomain.getDataSource();
} catch (NamingException ne) {
throw ne;
} catch (SQLException se) {
throw se;
}
}
}
public void initContext() throws SQLException{
ctx = DefaultContext.getDefaultContext();
if (ctx == null) {
try {
conn = dataSource.getConnection();
conn.setAutoCommit(false);
ctx = new DefaultContext(conn);
} catch (SQLException se) {
throw se;
}
DefaultContext.setDefaultContext(ctx);
}
}
Pls help. Thank you very much. -
8. Re: Is connection close needed?
jonlee Jun 12, 2003 7:09 AM (in response to lee_yuki2000)You don't need to close the connection after every SQL statement in the method of a stateless session bean. However, you must close it before you leave the method. Otherwise the connection will be unavailable to other requesters until the connection times out.
So let us look at a working routine for a stateless session bean method:
public void addEvent(EventEntry eventEntry)
{
DataSource dataSource = null;
if (genericInsert == null)
genericInsert = generateInsert(TABLE, ELEMENTLIST, HOLDERLIST);
if (eventEntry == null)
return;
// Find the JBoss pool (datasource - JNDI: OracleDS)
try
{
Context naming = new InitialContext();
dataSource = (DataSource)naming.lookup("java:/OracleDS");
}
catch(Exception e)
{
System.out.println(error + e.toString());
}
Connection connection = null;
if (dataSource != null)
try
{
connection = dataSource.getConnection();
}
catch(Exception e)
{
System.out.println(error + e.toString());
}
}
// Use the connection if we successfully got one
if (connection != null)
{
// Write an event using the connection
PreparedStatement insertEvent = null;
try
{
insertEvent = connection.prepareStatement(genericInsert);
insertEvent.setInt(1, eventEntry.getSeverity());
insertEvent.setString(2, eventEntry.getSystem().trim());
insertEvent.setString(3, eventEntry.getModule().trim());
insertEvent.executeUpdate();
}
catch(Exception e)
{
System.out.print("Event Logger Error: ");
System.out.println(e.toString());
System.out.print("Sql: ");
System.out.println(genericInsert);
generateMessage(eventEntry);
}
try
{
if (insertEvent != null)
insertEvent.close();
}
catch(Exception e)
{
System.out.print("Event Logger Error: ");
System.out.println(e.toString());
}
//... do some other things with the connection
// Release connection back to pool now we have finished
try
{
if (connection != null)
connection.close();
}
catch(Exception e)
{
System.out.print("Event Logger Error: ");
System.out.println(e.toString());
}
}
else
{
System.out.print("Event Logger Error: Could not create connection");
generateMessage(eventEntry);
}
} -
9. Re: Is connection close needed?
lee_yuki2000 Jun 13, 2003 8:07 AM (in response to lee_yuki2000)Jonlee,
Thank you very much -
10. Re: Is connection close needed?
kar2000 Jul 17, 2003 4:55 AM (in response to lee_yuki2000)Well, I have a doubt in this regard - is there any means of finding in the jboss 3.0.7 server side and not in the Oracle 8 database server side,
how many connections are there in the pool,
how many connections are in use and
how many connections are being returned at a given point of time? -
11. Re: Is connection close needed?
maralc Jul 23, 2003 3:45 PM (in response to lee_yuki2000)I have the same doubt as you.
Maralc