<%@ page contentType="text/html; charset=Shift_JIS" %> <%@ page import="java.sql.*,javahello.DBConnectionPool" %> <%! DBConnectionPool pool; %> <% Connection con = null; Statement stmt = null; try { // コネクションプールクラスのインスタンスを取得 pool = DBConnectionPool.getInstance(); // データベースへの接続を取得 con = pool.getConnection(); // ステートメントオブジェクトを生成 stmt = con.createStatement(); // 全ての行を検索するSQL文を作成 String sql = "SELECT * FROM HELLO_WORLD_TABLE"; // クエリーを実行して結果セットを取得 ResultSet rs = stmt.executeQuery(sql); %> JSPでDB接続 <% // 検索された行数分ループ while(rs.next()){ %> <% } // end while %>
NO 言語 メッセージ
<%=rs.getInt("NO") %> <%=rs.getString("LANGUAGE") %> <%=rs.getString("MESSAGE") %>
<% } catch (Exception e) { out.println("

エラー!

" + e); e.printStackTrace(); } finally { // データベースへの接続をクローズします try { if (stmt!=null) { stmt.close(); } } catch (Exception e) { e.printStackTrace(); } if (con!=null) { // データベースへの接続を返却します pool.freeConnection(con); } } %>