JDBC finally Block

Go back to: Code Samples
// Open a connection
Connection conn = null;
Statement st = null;
ResultSet rs = null;
 
try {
    ...
    conn = DriverManager.getConnection(connStr, uid, pwd);
    ...
    st = conn.prepareStatement(sqlString);
    ...
    rs = st.executeQuery();
    ...
    }
catch (SQLException e){
// exception handling code here
                      }
finally {
        try {
            if (rs != null)
            rs.close();
            if (st != null)
            st.close();
            if (conn != null)
            conn.close();
            }
catch (SQLException e) {
// exception handling code here
                      }
        }




Like what you see? Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis

Book Content Copyright © 2009 by Prentice Hall PTR. All rights reserved. | Corporate Sponsor DataDirect Technologies.