如何使用小脚本和表达式链接数据库输出emp表的数据
来源:互联网 发布:中国钓鱼运动协会数据 编辑:程序博客网 时间:2024/05/16 18:40
1、 在项目中配置oracle的驱动jar包
把jar包拷贝到项目中的lib文件夹下
然后把jar包部署在项目上边
2、 创建数据库工具类(提供数据库的链接、关闭链接、查询、更新的方法)DBOperation
3、 对emp表进行封装
新建Emp类 代码如下:
public class Emp {private int empno;private String ename;private String job;private int mgr;private Date hiredate;private int sal;private int comm;private int deptno;public int getEmpno() {return empno;}public void setEmpno(int empno) {this.empno = empno;}public String getEname() {return ename;}public void setEname(String ename) {this.ename = ename;}public String getJob() {return job;}public void setJob(String job) {this.job = job;}public int getMgr() {return mgr;}public void setMgr(int mgr) {this.mgr = mgr;}public Date getHiredate() {return hiredate;}public void setHiredate(Date hiredate) {this.hiredate = hiredate;}public int getSal() {return sal;}public void setSal(int sal) {this.sal = sal;}public int getComm() {return comm;}public void setComm(int comm) {this.comm = comm;}public int getDeptno() {return deptno;}public void setDeptno(int deptno) {this.deptno = deptno;}}
4、 新建EmpDao对emp表进行数据库操作
public class EmpDao extends DbOperation{//查询emp表数据public ArrayList select(){//集合对象用于保存查询到的数据ArrayList al=new ArrayList();//链接数据库getConn();//sql语句String sql="select * from emp";//执行查询extQuery(sql);//处理结果集try {while(rs.next()){Emp e=new Emp();e.setEmpno(rs.getInt("empno"));e.setEname(rs.getString("ename"));e.setJob(rs.getString("job"));e.setMgr(rs.getInt("mgr"));e.setComm(rs.getInt("comm"));e.setSal(rs.getInt("sal"));e.setDeptno(rs.getInt("deptno"));e.setHiredate(rs.getDate("hiredate"));al.add(e);}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}//关闭链接closeAll();return al;}}
5、 新建jsp来显示查询出的数据
<%@page import="myjsp.vo.Emp"%><%@page import="myjsp.dao.EmpDao"%><%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%//获得emp表数据EmpDao ed=new EmpDao();ArrayList al=ed.select();%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <title>My JSP 'emp.jsp' starting page</title> </head> <body> <table> <tr> <td>员工编号</td><td>员工姓名</td> <td>职位</td><td>上级编号</td> <td>入职日期</td><td>薪资</td> <td>奖金</td><td>部门编号</td> </tr> <%for(int i=0;i<al.size();i++){ Emp e=(Emp)al.get(i); out.print("<tr>"); out.print("<td>"+e.getEmpno()+"</td>"); out.print("<td>"+e.getEname()+"</td>"); out.print("<td>"+e.getJob()+"</td>"); out.print("<td>"+e.getMgr()+"</td>"); out.print("<td>"+e.getHiredate()+"</td>"); out.print("<td>"+e.getSal()+"</td>"); out.print("<td>"+e.getComm()+"</td>"); out.print("<td>"+e.getDeptno()+"</td>"); out.print("</tr>"); }%> </table> </body></html>
阅读全文
1 0
- 如何使用小脚本和表达式链接数据库输出emp表的数据
- 使用minus比对非LOB和LOB表的两个小脚本
- 如何编写简单的lua小脚本@@
- 剔除不能使用IP的小脚本
- 有用的小脚本
- 列出各个部门中工资高于本部门的平均工资的员工数和部门号,并按部门号排序(oracle数据库中的emp表)
- 数据库创建emp和dept练习表
- 自己用python写的性能专项小脚本原理和使用
- python用于url解码和中文解析的小脚本
- python用于url解码和中文解析的小脚本
- Jsp注释、小脚本、表达式、声明
- 监听tomcat的小脚本
- 实用的小脚本代码
- 切割头像的小脚本
- 一些有意思的小脚本
- 一个对帐的小脚本
- python 备份文件的小脚本
- JDBC连接Oracle数据库后实现对emp 表数据的增删改查
- compilation terminated. In file included from <command-line>:0:0: /usr/include/stdc-predef.h:30:26:
- python requests 和正则表达式提取贴吧图片
- ASimpleCache缓存框架之简单使用
- php 错误cannot-use-object-of-type-stdclass-as-array
- 查看Keil ARM各种数据类型占用的字节数
- 如何使用小脚本和表达式链接数据库输出emp表的数据
- 最小白_tomcat1.7的安装及配置
- 小白算法练习 安慰奶牛 最小生成树 lanqiao prim
- 微信小程序中用户信息解密
- C++类模版demo
- win2008/2012显示桌面图标
- 解决ListView中Item的子控件与Item点击事件冲突
- Docker常用命令
- 进程与线程的区别