📄 testdatabase.jsp
字号:
<%@page contentType="text/html"%><%@page pageEncoding="UTF-8"%><%@page import="java.sql.*" %><%@page import="javax.sql.DataSource" %><%@page import="javax.naming.Context" %><%@page import="javax.naming.InitialContext" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Test Database</title> </head> <body> <h1>Test Database</h1> <% /** int numStep=0; %><br>Step <%= numStep %> <% **/ DataSource datasource; Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { Context ctx = new InitialContext(); datasource = (DataSource) ctx.lookup("java:comp/env/jdbc/dvdLibraryDB"); con = datasource.getConnection(); String username = "jack"; String searchString = "SELECT id, title, \"year\", genre FROM Item WHERE username=?"; %><hr>Start list for <%= searchString %> : <%= username %> <% ps = con.prepareStatement(searchString); ps.setString(1, username); // puts parameter into a statement that the char "?". rs = ps.executeQuery(); while(rs.next()) { %><br>title = <%= rs.getString("title") %> <% } %><br>End list list.<hr><% } catch (Exception e) { e.printStackTrace(); } finally { if(rs != null) { try { rs.close(); } catch (Exception e) { e.printStackTrace(); %><hr><pre>rs</pre> <% } } if(ps != null) { try { ps.close(); } catch (Exception e) { e.printStackTrace(); %><hr><pre>ps</pre> <% } } if(con != null) { try { con.close(); } catch (Exception e) { e.printStackTrace(); %><hr><pre>con</pre> <% } } }%> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -