二 在Oracle数据库中建立表格,包含员工的工号、姓名、性别、工龄、工资等字段,并实现增删改查操作。
(1)所建的worker表格如下:
(2)Input.jsp运行结果如下:
(3)Inputcheck.jsp运行结果如下:
Pagebreak.jsp代码如下:
<%@page contentType="text/html"pageEncoding="UTF-8" import="java.sql.*"%>
分页显示记录内容
| 工号 | 姓名 | 性别 | 工龄 | 工资 |
|---|---|---|---|---|
| <%=rs.getString("id")%> | <%=rs.getString("name")%> | <%=rs.getString("sex")%> | <%=rs.getString("workyear")%> | <%=rs.getString("sal")%> |
第<%=intPage%>页 共<%=intPageCount%>页
<%
if(intPage <% } if(intPage>1){ %> <% } rs.close(); stmt.close(); con.close(); %>
Input.jsp代码如下:
<%@page contentType="text/html"pageEncoding="UTF-8"%>
Inputcheck.jsp 代码如下:
<%@page contentType="text/html"pageEncoding="UTF-8" import="java.sql.*"%>
<%
String empID = request.getParameter("empID");
byte []b=empID.getBytes("ISO-8859-1");
empID = new String(b,"UTF-8");
String empName = request.getParameter("empName");
byte []b1=empName.getBytes("ISO-8859-1");
empName = new String(b1,"UTF-8");
String empSex = request.getParameter("empSex");
byte []b2=empSex.getBytes("ISO-8859-1");
empSex = new String(b2,"UTF-8");
String empWorkyear= request.getParameter("empWorkyear");
byte []b3=empWorkyear.getBytes("ISO-8859-1");
empWorkyear = new String(b3,"UTF-8");
String empSal = request.getParameter("empSal");
byte []b4=empSal.getBytes("ISO-8859-1");
empSal = new String(b4,"UTF-8");
String oracledriver="oracle.jdbc.driver.OracleDriver";
String oracleUrl="jdbc:oracle:thin:@localhost:1521:ORACLE";
String username="scott";
String password="tiger";
Class.forName(oracledriver);
Connection con=DriverManager.getConnection(oracleUrl,username,password);
Statement stmt=con.createStatement();
String sql="insert into worker values('" +empID +"','"+empName+"','"+empSex+"',"+empWorkyear+
stmt.executeUpdate(sql);
stmt.close();
con.close();
%>
<%
String oracledriver1="oracle.jdbc.driver.OracleDriver";
String oracleUrl1="jdbc:oracle:thin:@localhost:1521:ORACLE";
String username1="scott";
String password1="tiger";
Class.forName(oracledriver1);
Connection con1=DriverManager.getConnection(oracleUrl1,username1,password1);
Statement stmt1=con1.createStatement();
String sql1="delete from worker where empName='韩信'";
stmt1.executeUpdate(sql1);
stmt1.close();
con1.close();
%>
<%
String oracledriver2="oracle.jdbc.driver.OracleDriver";
String oracleUrl2="jdbc:oracle:thin:@localhost:1521:ORACLE";
String username2="scott";
String password2="tiger";
Class.forName(oracledriver2);
Connection con2=DriverManager.getConnection(oracleUrl2,username2,password2);
Statement stmt2=con2.createStatement();
String sql2="update worker set empName='李莉莉' where empName='Kababa'";
stmt2.executeUpdate(sql2);
stmt2.close();
con2.close();
%>
| 编号 | 姓名 | 性别 | 工龄 | 工资 |
| <%=rs.getString("empID")%> | <%=rs.getString("empName")%> | <%=rs.getString("empSex")%> | <%=rs.getString("empWorkyear")%> | <%=rs.getString("empSal")%> |