Michael Ni wrote:

public ResultSet getData(String queryStr) throws Exception
    {

        try {
            DBConstants db = new DBConstants();
            Class.forName(db.getDrivername());
            Connection conn;
conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://" + db.getHostname() + "","" + db.getUsername() + "","" + db.getPassword() + "");


            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery(queryStr);
            return rs;
        }
        catch(Exception e) {
            e.printStackTrace();
            System.out.println("getData error");
            throw new Exception();
        }
    }

Add

|finally {
     try {if (rs != null) rs.close();} catch (SQLException e) {}
     try {if (stmt != null) stmt.close();} catch (SQLException e) {}
     try {if (conn != null) conn.close();} catch (SQLException e) {}
   }|

And return an object rather than ResultSet.

Read about connection pooling, here is an example:
http://www.onjava.com/pub/a/onjava/2006/04/19/database-connection-pooling-with-tomcat.html?page=1

--
Darek Czarkowski
www.infinitesource.ca
darekc at infinitesource dot ca

---------------------------------------------------------------------
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