1 23 24 package org.dbforms.taglib; 25 26 import org.dbforms.util.SqlUtil; 27 28 import java.sql.Connection ; 29 30 import javax.servlet.jsp.JspException ; 31 import javax.servlet.jsp.PageContext ; 32 33 34 35 39 public class DbGetConnection extends TagSupportWithScriptHandler 40 implements javax.servlet.jsp.tagext.TryCatchFinally { 41 private transient Connection conn; 42 private String dbConnectionName; 43 44 49 public void setConn(Connection connection) { 50 conn = connection; 51 } 52 53 54 59 public Connection getConn() { 60 return conn; 61 } 62 63 64 69 public void setDbConnectionName(String name) { 70 dbConnectionName = name; 71 } 72 73 74 79 public String getDbConnectionName() { 80 return dbConnectionName; 81 } 82 83 84 87 public void doCatch(Throwable t) throws Throwable { 88 throw t; 89 } 90 91 92 100 public int doEndTag() throws javax.servlet.jsp.JspException { 101 try { 102 SqlUtil.closeConnection(this.getConn()); 104 this.setConn(null); 105 pageContext.removeAttribute(getId(), PageContext.PAGE_SCOPE); 106 } catch (Exception e) { 107 throw new JspException ("Connection error" + e.getMessage()); 108 } 109 110 return EVAL_PAGE; 111 } 112 113 114 117 public void doFinally() { 118 dbConnectionName = null; 119 } 120 121 122 130 public int doStartTag() throws JspException { 131 try { 132 this.setConn(getConfig().getConnection(dbConnectionName)); 134 pageContext.setAttribute(getId(), this.getConn(), 135 PageContext.PAGE_SCOPE); 136 } catch (Exception e) { 137 throw new JspException ("Connection error" + e.getMessage()); 138 } 139 140 return EVAL_BODY_INCLUDE; 141 } 142 } 143 | Popular Tags |