jdbc连接oracle_JDBC连接oracle数据库做jsp页面

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值