[jboss-user] [Beginners Corner] - Managed Connection Pools
do-not-reply at jboss.com
Thu Jul 13 19:12:22 EDT 2006
I am getting the 'NoManagedConnections' Exception this only happens after a while, but I confess I am confused by the JBoss documentation and the few examples of servlets working with JBoss don't seem to be much help.
I get a new connection object when I call the init method of each of my servlets (there are about 20), that is the only connection object I use for that servlet (I pass it as a parameter to the various factory classes I use within the servlet to do database access).
But if I understand correctly, there is only one instance of each servlet - so it shoud only be using one connection? So I should only be using the same number of connections as servlets?
Do I really need to close and create connections whenever I use JDBC?
Is there somewhere I can put a close command that wouldn't be too much rework? Or is there a timeout for spotting dead connections?
I already have a fairly large application and this would be painful to put it mildly... I thought that was the point of a managed connection pool? I have included the datasource XML file and also the code for getting a connection.
Thank-you in advance
I have project-ds.xml file to set-up a connection pool with Postgres:
| <type-mapping>PostgreSQL 8.0</type-mapping>
I use a JNDI call to get a connection from that pool:
| public Connection getConnection() throws SQLException
| Connection conn = null;
| Context ctx = null;
| DataSource ds = null;
| String sourceName = "";
| ctx = new InitialContext();
| if(ctx == null )
| throw new NamingException("Error 'Db.getConnection' - No Context");
| sourceName = this.getDbName(ctx);
| ds = (DataSource)ctx.lookup(sourceName);
| catch (NamingException e)
| catch (Exception e)
| if (ds != null)
| conn = ds.getConnection();
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3957921#3957921
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3957921
More information about the jboss-user