I'm using JBoss AS 7.1 as a server and I have my DataSource configured with pooling. I'm quite new to this so please excuse any rookie mistakes... after all I'm here to learn.
When a client logs-in it gets a connection to the database and I need to keep that connection(from the pool) open until the user logs-out or the HttpSession expires. This is an absolute requirement coming from our DB Admin. who says that he needs the DB session variables. I am using a servlet for all this.
Playing with the possibilities I have encountered 2 major problems:
As far as I see JBoss automatically closes unused connections => my opened connection returns to the pool. So this might not be the right path.
If I try to store/recall the Connection object like this:
private Hashtable<String, Connection> connections = new Hashtable<String, Connection>(); try { String strDSName1 = "java:/OracleDSJNDI"; ctx = new InitialContext(); ds1 = (javax.sql.DataSource) ctx.lookup(strDSName1); System.out.println("Got 1'st ds."); } catch (Exception e) { System.out.println("ERROR getting 1'st DS : " + e); } connection = ds1.getConnection(); connections.put(session.getId(), connection); conn = (Connection) connections.get(sessionID);
it throws this exception:
java.sql.SQLException: Connection is not associated with a managed connection.org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6@dee1f37
My question is: How do I properly keep my connection opened?
Thanks