日期:2014-05-16 浏览次数:20625 次
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*"%> <html> <body> 以下是从MySQL数据库读取的数据:</hr> <% Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection con = DriverManager.getConnection("jdbc:mysql://127.0.0.1/test","root","root"); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select * from employee WHERE salary>3000"); out.print("<table border=2>"); out.print("<tr>"); out.print("<th width=100>"+"雇员号"); out.print("<th width=100>"+"姓名"); out.print("<th width=50>"+"出生日期"); out.print("<th width=50>"+"薪水"); out.print("</tr>"); while(rs.next()){ out.print("<tr>"); out.print("<td>"+rs.getString("id")+"</td>"); out.print("<td>"+rs.getString("name")+"</td>"); out.print("<td>"+rs.getString("birthday")+"</td>"); out.print("<td>"+rs.getString("salary")+"</td>"); out.print("</tr>"); } out.print("</table"); stmt.close(); con.close(); %> </body> </html>