%@page language="Java" isErrorPage="false" import=" java.sql.*, java.util.*, java.io.PrintWriter, java.io.StringWriter, javax.naming.Context, javax.naming.InitialContext, javax.naming.NamingException, javax.sql.DataSource " session="false" pageEncoding="utf-8" %> <%@ include file="htmlescape.jsp" %> <%! /** * Gets a JDBC connection. This implementation uses JNDI to obtain a * connection. Feel free to substitute your own. */ Connection getConnection() throws SQLException, javax.naming.NamingException { Context ctx = new InitialContext(); DataSource ds = (DataSource)ctx.lookup("java:/comp/env/jdbc/myDataSource"); if(null == ds) throw new NamingException("Cannot obtain DataSource"); return ds.getConnection(); } %> <% String query = request.getParameter("q"); String title = request.getParameter("title"); boolean showQuery = (!"false".equals(request.getParameter("showQuery"))); boolean preformattedResults = ("true".equalsIgnoreCase(request.getParameter("preformattedResults"))); boolean escapeHtml = (!"false".equalsIgnoreCase(request.getParameter("escapeHtml"))); boolean tallFormat = ("true".equalsIgnoreCase(request.getParameter("tallFormat"))); boolean showAllOptions = ("true".equalsIgnoreCase(request.getParameter("showAllOptions"))); boolean hasTitle = (null != title && 0 < title.trim().length()); boolean hasQuery = (null != query && 0 < query.trim().length()); if(!hasQuery) query = ""; else query = query.trim(); if(hasTitle) title = htmlescape(title); %>
<% if (hasTitle) { %><%= rsmd.getColumnLabel(i + 1) %> | <% } } %>|
---|---|
Row <%= rowCount %> | |
<%= rsmd.getColumnLabel(1 + i) %> | <% } %>
<% if(preformattedResults) { %><% } %><%= (escapeHtml ? htmlescape(value) : value) %><% if(preformattedResults) { %><% } %> |
<%
if(tallFormat) {
%>
Query produced <%= rowCount %> results in <%= queryTime %>ms. Results were rendered in <%= renderTime %>ms.
<% if(hasQuery) query = htmlescape(query); if(showQuery) { %>Query:
<%= query %><% } } catch (SQLException sqle) { %>
There was an error executing your query: (See page source for details)
<%= sqle.getMessage() %>
<% } finally { if(null != rs) try { rs.close(); } catch (SQLException sqle) { getServletContext().log("Cannot close ResultSet", sqle); } if(null != s) try { s.close(); } catch (SQLException sqle) { getServletContext().log("Cannot close Statement", sqle); } if(null != conn) try { conn.close(); } catch (SQLException sqle) { getServletContext().log("Cannot close Connection", sqle); } } %> <% } %> <% if(showQuery) { %> <% } %>This work is licensed under a Creative Commons License.