Datasql.java package data;import java.sql.*;public class Datasql { private final String url="127.0.0.1/"; private final String database="book"; private final String usename="root"; private final String password="yy3948389"; private final String driver="com.mysql.jdbc.Driver"; private String connstr="jdbc:mysql://"; private String sqlstr; Connection conn=null; ResultSet rs=null; Statement stmt=null; public Datasql(){ try{ conn=openconn(); stmt=conn.createStatement(); }catch(Exception e){ System.err.println("无法连接数据库"); } } public Connection openconn()throws Exception,SQLException{ try{ Class.forName(driver).newInstance(); }catch(Exception e){ System.err.println("无法加载驱动"); } return conn=DriverManager.getConnection(connstr+url+database,usename,password); } public ResultSet select(String sqlstr){ this.sqlstr=sqlstr; try{ rs=stmt.executeQuery(sqlstr); }catch(SQLException e){ System.err.println(sqlstr+":失败"); } return rs; } public boolean updata(String sqlstr){ this.sqlstr=sqlstr; try{ stmt.executeUpdate(sqlstr); return true; }catch(SQLException e){ System.err.println(sqlstr+":失败"); return false; } } public boolean insert(String sqlstr){ this.sqlstr=sqlstr; try{ stmt.executeUpdate(sqlstr); return true; }catch(SQLException e){ System.err.println(sqlstr+":失败"); return false; } } public boolean delete(String sqlstr){ this.sqlstr=sqlstr; try{ stmt.executeUpdate(sqlstr); return true; }catch(SQLException e){ System.err.println(sqlstr+":失败"); return false; } } public boolean close(){ try{ if(rs!=null){ rs.close(); } if(stmt!=null){ stmt.close(); } if(conn!=null){ conn.close(); } return true; }catch(Exception e){ System.err.println("关闭失败!"); return false; } }} show.jsp <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>管理员</title></head><style type="text/css"><!--.STYLE1 { font-size: 14px; color: #FFFFFF; font-weight: bold; font-family: "宋体";}body,td,th { font-family: 宋体; font-size: 12px; color: #000000;}body { margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px;}--></style><body><jsp:useBean id="sqlbean" scope="page" class="data.Datasql"/><table width="80%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC"> <tr> <td height="30" colspan="2" align="center" valign="middle" bgcolor="#0099FF"><span class="STYLE1">管理员列表<%=new java.text.SimpleDateFormat(" yyyy 年 d 月 mm 日").format(new java.util.Date())%></span></td> </tr><%ResultSet rs=sqlbean.select("select name from admin");int i=0;while(rs.next()){String name=rs.getString("name");i++;%> <tr> <td width="15%" height="20" align="center" valign="middle"><%=i%></td> <td width="85%" align="center" valign="middle"><%=name%></td> </tr><%}if(!sqlbean.close()){ out.println("关闭链接失败");}%></table></body></html>