<%-- Document : test3 Created on : 2010-4-21, 15:49:23 Author : Administrator --%> <%@page import="rec.DBUtil,java.sql.*"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www./TR/html4/loose.dtd">
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <% DBUtil db = new DBUtil(); Connection conn = db.getConn(); String sql = "select top 5 * from qk"; //out.print(conn); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql); Connection conn2 = db.getConn(); Statement stmt2 = conn2.createStatement(); while (rs.next()) { int id = rs.getInt(1); out.print(id); out.print(rs.getString(2)); String sql2 = "select * from test2 where id=" + id; ResultSet rs2 = stmt2.executeQuery(sql2); out.print("<br>" + sql2 + "<br>"); while (rs2.next()) { out.print(rs2.getString("infor")); } out.print("<br>------------<br>"); rs2.close(); } stmt2.close(); conn2.close(); conn.close(); //out.print(rs.next()); /* String sql = "select * from qk where id =?"; PreparedStatement pst = conn.prepareStatement(sql); pst.setInt(1, 7257); ResultSet rs = pst.executeQuery(); if (rs.next()) { int id = rs.getInt(1); out.print(id); out.print(rs.getString(2)); String sql2 = "select * from test2 where id=" + id; Connection conn2 = db.getConn(); Statement stmt2 = conn2.createStatement(); ResultSet rs2 = stmt2.executeQuery(sql2); out.print("<br>"+sql2+"<br>"); while (rs2.next()) { out.print(rs2.getString("infor")); } rs2.close(); stmt2.close(); conn2.close(); conn.close();
} * */ %> <br> over! </body> </html>
|