DBHper类:
public class DBHper {private static final String Driver= "oracle.jdbc.driver.OracleDriver";private static final String url="jdbc:oracle:thin:@127.0.0.1:1521:ORCL";private static final String uid="scott";private static final String pwd="tiger";private static Connection con=null;private static ResultSet rst=null;private static PreparedStatement pst=null;public static Connection getcon() {try {Class.forName(Driver);con=DriverManager.getConnection(url,uid,pwd);} catch (Exception e) {e.printStackTrace();}return con;}public static ResultSet runSelectSql(String sql){try {con=getcon();pst=con.prepareStatement(sql);rst=pst.executeQuery();// rs=ResultSupport.toResult(rst);} catch (Exception e) {e.printStackTrace();}return rst;}}
Emp实体类
private int empno;private String ename;private String job;private String job;private int mgr;private Date hiredate;private float sal;private float comm;private int deptno;public Emp(int empno, String ename, String job, int mgr, Date hiredate, float sal, float comm, int deptno) {super();this.empno = empno;this.ename = ename;this.job = job;this.mgr = mgr;this.hiredate = hiredate;this.sal = sal;this.comm = comm;this.deptno = deptno;}getter和setter方法省略。。。。。import java.io.IOException;import java.io.PrintWriter;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.Date;import java.util.List;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;Dwy1 Servlet类public class Dwy1 extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {this.doPost(request, response);}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {response.setHeader("content-type", "text/html;charset=UTF-8");PrintWriter out = response.getWriter();String sql="select * from emp";ResultSet rst=DBHper.runSelectSql(sql);if(rst !=null){List list=new ArrayList();try {while(rst.next()){int empno=Integer.parseInt(rst.getInt("empno")+"");String name=rst.getString("ename");String job=rst.getString("job");int mgr=rst.getInt("mgr");Date hiredate=rst.getDate("hiredate");float sal=rst.getFloat("sal");float comm=rst.getFloat("comm");int deptno=rst.getInt("deptno");Emp shop=new Emp(empno, name, job, mgr, hiredate, sal, comm, deptno);list.add(shop);}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{try {rst.close();} catch (Exception e2) {e2.printStackTrace();}}request.setAttribute("list", list);request.getRequestDispatcher("show.jsp").forward(request, response);}else {out.print("没有找到会员");}out.flush();out.close();}}
web.xml
Dwy1com.Dwy1Dwy1/dwy1 show.jsp页面My JSP 'index.jsp' starting page
会员信息如下:
编号姓名岗位入职时间薪水提成
![c1e290409515d57f0d1ce763be4529e0.png](https://i-blog.csdnimg.cn/blog_migrate/4a241a5da9f45e07c2ac6d8d74280b00.jpeg)