1 23 package org.dbforms.taglib; 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 27 import org.dbforms.config.DbEventInterceptorData; 28 import org.dbforms.config.ResultSetVector; 29 30 import java.sql.Connection ; 31 import java.sql.PreparedStatement ; 32 import java.sql.SQLException ; 33 34 import java.util.List ; 35 36 import javax.servlet.http.HttpServletRequest ; 37 38 39 40 67 public class QueryData extends EmbeddedData 68 implements javax.servlet.jsp.tagext.TryCatchFinally { 69 private static Log logCat = LogFactory.getLog(QueryData.class.getName()); 70 71 private String query; 73 74 79 public void setQuery(String query) { 80 this.query = query; 81 } 82 83 84 89 public String getQuery() { 90 return query; 91 } 92 93 94 97 public void doCatch(Throwable t) throws Throwable { 98 throw t; 99 } 100 101 102 105 public void doFinally() { 106 query = null; 107 super.doFinally(); 108 } 109 110 111 121 protected List fetchData(Connection con) throws SQLException { 122 logCat.info("about to execute user defined query:" + query); 123 124 ResultSetVector rsv = null; 125 PreparedStatement ps = con.prepareStatement(query); 126 127 try { 128 rsv = new ResultSetVector(); 129 130 HttpServletRequest request = (HttpServletRequest ) pageContext 131 .getRequest(); 132 DbEventInterceptorData data = new DbEventInterceptorData(request, 133 getConfig(), con, null); 134 data.setAttribute(DbEventInterceptorData.PAGECONTEXT, 135 pageContext); 136 rsv.addResultSet(data, ps.executeQuery()); 137 } finally { 138 ps.close(); } 140 141 return formatEmbeddedResultRows(rsv); 142 } 143 } 144 | Popular Tags |