users@glassfish.java.net

Re: JDBC SQLException: max pool size exceeded

From: <glassfish_at_javadesktop.org>
Date: Wed, 02 Jul 2008 05:41:22 PDT

I thought that might be the problem, so I rechecked my code. I open the connection at the beginning of the query and close it after the end, so if it is, I'm not sure how:

[code]
public void connect()
    throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException, NamingException {
        if (getResourceName() != null) {
            InitialContext oContext = new InitialContext();
            DataSource oDataSource = (DataSource) oContext.lookup(getResourceName());
            oConn = oDataSource.getConnection();
        } else if (getUsername() != null) {
            Class.forName(sDriver).newInstance();
            oConn = DriverManager.getConnection(sDatabase, sUserName, sPassword);
        } else {
            throw new IllegalAccessException("Neither Resource Name nor User Name is set.");
        }
        
        bConnected = true;
    }

public void close() {

        try {
            oConn.close();
        } catch (Exception eException) {

        //Ignore any errors here.
        }

    }

public ArrayList<ArrayList<String>> query(String sSelectStatement)
            throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException, NamingException {
        if (sSelectStatement.toLowerCase().startsWith("update")) {
            String sErrMsg = "Query is not a SELECT statement. Use the update() method to insert records.";
            throw new IllegalArgumentException(sErrMsg);
        } else {
            this.connect();
            Statement oStatement = oConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            ResultSet oResults = oStatement.executeQuery(sSelectStatement);

            oResults.last();
            this.iRecordsReturned = oResults.getRow();
            oResults.beforeFirst();

            int iColumns = oResults.getMetaData().getColumnCount();
            ArrayList<ArrayList<String>> aResults = new ArrayList<ArrayList<String>>();

            while (oResults.next()) {
                ArrayList<String> aTemp = new ArrayList<String>();
                for (int iIterator = 1; iIterator <= iColumns; iIterator++) {
                    aTemp.add(oResults.getString(iIterator));
                }

                aResults.add(aTemp);
            }

            oResults.close();
            oStatement.close();
            this.close();
            return aResults;
        }
    }
[/code]
[Message sent by forum member 'malakh' (malakh)]

http://forums.java.net/jive/thread.jspa?messageID=283950