1 16 package web.struts; 17 18 import java.sql.*; 19 import javax.servlet.ServletContext ; 20 import javax.sql.DataSource ; 21 22 import org.apache.struts.Globals; 23 import org.apache.struts.action.ActionForm; 24 25 29 public abstract class ActionFormExtend extends ActionForm { 30 31 36 protected Connection getConnection() throws SQLException { 37 ServletContext context = servlet.getServletContext(); 38 DataSource dataSource = (DataSource ) context 39 .getAttribute(Globals.DATA_SOURCE_KEY); 40 return dataSource.getConnection(); 41 } 42 43 48 protected Connection getConnection(String key) throws SQLException { 49 ServletContext context = servlet.getServletContext(); 50 DataSource dataSource = (DataSource ) context.getAttribute(key); 51 return dataSource.getConnection(); 52 } 53 54 60 protected void close(ResultSet rs, Statement stmt, Connection conn) { 61 if (rs != null) 62 try { 63 rs.close(); 64 } catch (Exception exception) { 65 } 66 if (stmt != null) 67 try { 68 stmt.close(); 69 } catch (Exception exception1) { 70 } 71 if (conn != null) 72 try { 73 conn.close(); 74 } catch (Exception exception2) { 75 } 76 } 77 } | Popular Tags |