Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
<%@page contentType="text/html" pageEncoding="UTF-8"
<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<table border="1">
Connection db = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
Context context = new InitialContext();
DataSource ds = (DataSource)context.lookup("jdbc/BOOKS");
db = ds.getConnection();
ps = db.prepareStatement("SELECT * FROM books WHERE title LIKE ?");
ps.setString(1, "%" + request.getParameter("searcher") + "%");
rs = ps.executeQuery();
while( {
<td><%=rs.getString("name") %></td>
<td><%=rs.getString("year") %></td>
<td><%=rs.getString("title") %></td>
<td><%=rs.getString("publisher") %></td>
} catch(Exception e) {
throw new ServletException(e);
} finally {
if(rs != null) {rs.close();}
if(ps != null) {ps.close();}
if(db != null) {db.close();}
}catch(Exception e) {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment