> -----BEGIN PGP SIGNED MESSAGE-----
>
> Are you using a connection pool? If so, which one?
>

I'm trying to figure this out.  I don't see any evidence of one configured
in the server.xml file.   If not, I presume it would be a good idea for us
to start using one?

> You need to make sure that you call "close" on /everything/ when you're
> done with your Connection, Statement (and subclass), and ResultSet (and
> subclass) objects. Check to make sure that those close calls are done in
> "finally" blocks, and that a failure to close a ResultSet does not cause
> an exception to be thrown that avoids the Connection close.
>
> For example:
>
> Connection conn = getConnection();
>
> PreparedStatement ps = conn.prepareStatement("SELECT 1");
>
> ResultSet rs = ps.executeQuery();
>
> ...
>
> rs.close();
> ps.close();
> conn.close();
>
> return null;
>
> This is not good. What you really need is this:
>
> Connection conn = null;
> PreparedStatement ps = null;
> ResultSet rs = null;
>
> try
> {
> ~    conn = getConnection();
> ~    ps = ...;
> ~    rs = ...;
>
> ~    ...
> }
> finally
> {
> ~    if(null != rs)
> ~        try { rs.close(); } catch (SQLException sqle) { /* log */ }
> ~    if(null != ps)
> ~        try { ps.close(); } catch (SQLException sqle) { /* log */ }
> ~    if(null != conn)
> ~        try { conn.close(); } catch (SQLException sqle) { /* log */ }
> }
>
> Note how all the cleanup is done in the finally block (so the cleanup
> code will run even during an exception situation), and that each "close"
> is called in its own try/catch block: this prevents the failure to close
> the (e.g.) ResultSet from preventing the Statement or Connection from
> closing. Remember to log anything weird.
>


The calls look like this:

public void testXXX(DataSource ds, String login) {
    PreparedStatement ps=null;
    ResultSet rs=null;

    try {
        conn = ds.getconnection();
        ps = conn.prepareStatement("SELECT * from test");
        ps.setString(1,login);
        rs = ps.executeQuery();
        if(rs.next()){
            //do something with the data
        }
    }catch (Exception e) {
        System.out.println("Exception: " + e);
        e.printStackTrace();
    }
    finally {
            try {
                try {
                    if(rs != null) rs.close();rs=null;
                } catch (Exception e) {
                    e.printStackTrace();
                }
                try {
                    if (ps != null) ps.close();ps=null;
                } catch (Exception e) {
                    e.printStackTrace();
                }
                try {
                    if(conn != null || conn.isClosed()) conn.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
    }

}

I see that we are not using specifically catching "SQLException sqle" -
should we be?

Further info on our system (sorry for the earlier omission):

We are running Red Hat Enterprise Linux 4.0
Tomcat 5.5
Java 1.5.0_11

I also found two different mysql connector files.  I'm not sure which one
(if either) is being used:

mysql-connector-java-3.1.14-bin.jar
mysql-connector-java-5.0.0-beta-bin.jar



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to