Title: Message

Thanks for the tip.  I rewrote the code like you suggested and I’m still getting the warning.  Any more ideas?

 

Mike

 

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Rod Macpherson
Sent: Thursday, October 09, 2003 7:12 PM
To: [EMAIL PROTECTED]
Subject: RE: [JBoss-user] Quick JDBC question.

 

I would structure this as follows to make sure the ResultSet is always closed and also so that you do not get a null pointer if the prepare statement throws:

 

blah blah blah...

 

finally

{

    try

    {

        if(result != null) result.close();

        if(statement != null) statement.close();

        if(connection != null) connection.close();

    }

    catch(SQLException e)

    {

        logger.error("whaddup?");

    }

}

 

 

-----Original Message-----
From: Mike Youngstrom [mailto:[EMAIL PROTECTED]
Sent: Thursday, October 09, 2003 5:35 PM
To: [EMAIL PROTECTED]
Subject: RE: [JBoss-user] Quick JDBC question.

Let me add a little more information.

 

Version: JBoss 3.2.2 RC3

DBServer Mysql 4.0.15 Windows

JDBCDriver: Connector/J 3.0.8

 

Mike

 

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Mike Youngstrom
Sent: Thursday, October 09, 2003 10:38 AM
To: [EMAIL PROTECTED]
Subject: [JBoss-user] Quick JDBC question.

 

I’m fairly new to JDBC development and JBoss.  I have the following code in a stateless session bean.

 

            try {

                  boolean exists;

                  prepStmt = conn.prepareStatement(USERNAME_EXISTS);

                  prepStmt.setString(1, username);

                  ResultSet result = prepStmt.executeQuery();

                  exists = result.next();

                  result.close();

                  return exists;

            } catch (EJBException e) {

                  log.error("Error checking if username exists: ", e);

                  throw new EJBException(e);

            } finally {

                  try {

                        prepStmt.close();

                  } catch (Exception e) {/* Do Nothing */}

                  try {

                        conn.close();

                  } catch (Exception e) {/* Do Nothing */}

 

            }

 

Every time I execute the above method I get the following log entry:

 

WARN  [WrappedConnection] Closing a statement you left open, please do your own housekeeping

 

Any idea what I’m doing to warrant that warning?  When I step through the code with a debugger prepStmt.close() is executed with no exception and when conn.close() is executed that warning pops up.  prepStmt is the only statement I’m creating with that connection.  Anyone have any ideas?

 

Mike

Reply via email to