<%@ page contentType="text/html;charset=gb2312" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>使用Bean访问数据库</title>

</head>
<body>
<%@ page language="java" import="java.sql.*" %>
<!--引用javaBean-->
<jsp:useBean id="TestBean" scope="page" class="DataBase.MyDbBean" />
 
<%
//调用OpenConn方法与数据库建连接
 TestBean.OpenConn("try","sa","");
 String sql="select * from EMPLOYEE";
//调用executeQuery方法执行SQL语句，返回记录集
 ResultSet rs = TestBean.executeQuery(sql);
//遍历记录集，输出所有记录
 while (rs.next())
 {
//输出当前一条记录
//rs.getMetaData().getColumnCount()获得记录的字段数 
  for(int j=1; j<=rs.getMetaData().getColumnCount(); j++)
    {
//获得指定编号字段的值
   out.print( rs.getObject(j)+"\t");
    }
//换行
   out.println("<BR>");    
  }
  TestBean.closeStmt();
  TestBean.closeConn();
  %>

</body>
</html>
