This is the code:
package beans;
import java.sql.*;
import java.util.ArrayList;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
public class DbBean {
private static DataSource pool;
public static DataSource getPool() {
return pool;
}
public static void makePool() throws Exception{
try{
Context env = (Context) new
InitialContext().lookup("java:comp/env");
//Look up a DataSource, which represents a connection pool
pool = (DataSource)env.lookup("jdbc/OracleDS");
if (pool == null)
throw new Exception("'OracleDS' is an unknown
DataSource");
} catch (NamingException ne){
throw new Exception(ne.getMessage());
}
}
//method used for fetching data (only 1 column)
public ArrayList getSelect(String sql){
Statement st = null;
ArrayList arrList = new ArrayList();
Connection connection = null;
try {
connection = pool.getConnection();
st = connection.createStatement();
} catch (SQLException e1) {
e1.printStackTrace();
}
try{
ResultSet rs = st.executeQuery(sql);
while(rs.next()){
arrList.add(rs.getObject(1));
}
rs.close();
st.close();
connection.close();
}
catch (SQLException e) {
e.printStackTrace();
}
return arrList;
}
//method used for checking login access
public boolean getLogin(String sql) {
Statement st = null;
ResultSet rs = null;
boolean found = false;
Connection connection = null;
try {
connection = pool.getConnection();
st = connection.createStatement();
rs = st.executeQuery(sql);
if (rs.next())
found = true;
else
found = false;
rs.close();
st.close();
connection.close();
} catch (SQLException e1) {
e1.printStackTrace();
}
return found;
}
}
When I say connection.close() , the connection is given back to the pool. Am I wrong ?
How is it possible that my pool is running out of connections?
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3835801#3835801
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3835801
---
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
___
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user