对teacher表进行增加,删除,修改
<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>教师信息</title>
</head>
<body>
<div align="center"><font size="20px">教师信息表</font></div>
<table border="1" cellspacing="0" width="80%" align="center" style="text-align: center">
<tr>
<td height="40">职工编号</td>
<td >姓名</td>
<td >性别</td>
<td >生日</td>
<td >职称</td>
<td >专业</td>
<td>数据处理</td>
</tr>
<%
try
{ Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "test", "5211314");
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("select * from TEACHER"); if(rs!=null)
{
SimpleDateFormat sdf= new SimpleDateFormat("MM-dd-yyyy"); while(rs.next())
{
String tno = rs.getString(1);
String tname = rs.getString(2);
String tsex = rs.getString(3); String tbirthday=null;
if(rs.getDate(4)!=null)
{
tbirthday=sdf.format(rs.getDate(4));
}
String prof = rs.getString(5);
String depart = rs.getString(6);
%>
<tr>
<td height="40"><%=tno %></td>
<td><%=tname%></td>
<td><%=tsex%></td>
<td><%=tbirthday==null?"":tbirthday %></td>
<td><%=prof==null?"":prof %></td>
<td><%=depart%></td>
<td><a href='updateT.jsp?tno=<%=tno%>'><input type="button" value="修改"></a>
<a href='DeleteT?tno=<%=tno%>' onClick="delcfm()"><input type="button" value="删除"></a></td>
</tr> <%
}
rs.close();
} st.close();
conn.close(); }
catch(Exception e)
{
e.printStackTrace();
}
%>
<tr><td colspan="7" height="40"><a href="teacherInsert.jsp"><input type="button" value="添加教师信息"></a></td></tr>
</table>
<script language="javascript">
function delcfm() {
if (!confirm("确认要删除?")) {
window.event.returnValue = false;
}
}
</script>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加信息</title>
</head>
<body>
<form action="SaveT" method="post">
编号:<input type="text" name="tno"><br>
姓名:<input type="text" name="tname"><br>
性别:<input type="text" name="tsex"><br>
生日:<input type="text" name="tbirthday"><br>
职称:<input type="text" name="prof"><br>
专业:<input type="text" name="depart"><br>
<input type="submit" value="保存">
</form>
</body>
</html>
<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改</title>
</head>
<body>
<% try{
String tno=request.getParameter("tno");
String tname=null;
String tsex=null;
String tbirthday=null;
String prof=null;
String depart=null;
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
if(tno!=null && tno.trim().length()>0)
{
try {
Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "test", "5211314"); PreparedStatement p=conn.prepareStatement(
"select * from TEACHER where tno=?"); p.setString(1, tno); ResultSet rs=p.executeQuery();
if(rs!=null&&rs.next())
{
tname=rs.getString("tname");
tsex=rs.getString("tsex"); prof=rs.getString("prof");
depart=rs.getString("depart");
%>
<form action="SaveT" method="post">
编号:<input type="text" name="tno" readonly="readonly" value="<%=tno %>"><br>
姓名:<input type="text" name="tname" value="<%=tname %>"><br>
性别:<input type="text" name="tsex" value="<%=tsex%>"><br>
生日:<input type="text" name="tbirthday" value="<%=rs.getDate("tbirthday")==null?"":sdf.format(rs.getDate("tbirthday")) %>"><br>
职称:<input type="text" name="prof" value="<%=prof==null?"":prof%>"><br>
专业:<input type="text" name="depart" value="<%=depart %>"><br>
<input type="hidden" name="isupdate" value="1">
<a onClick="delcfm()"><input type="submit" value="保存"></a>
</form>
<%
rs.close(); }
else
{
out.print("未查询到数据");
} p.close();
conn.close(); } catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace(); }
}
else
{
out.print("请正确访问");
} }catch(Exception e)
{
}
%>
<script language="javascript">
function delcfm() {
if (!confirm("确认对信息的修改?")) {
window.event.returnValue = false;
}
}
</script>
</body>
</html>
package teacher;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import oracle.net.aso.e; public class SaveT extends HttpServlet {
private static final long serialVersionUID = 1L; public SaveT() {
super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String tno=request.getParameter("tno");
String tname=request.getParameter("tname");
String tsex=request.getParameter("tsex");
String tbirthday=request.getParameter("tbirthday");
String prof=request.getParameter("prof");
String depart=request.getParameter("depart");
String isupdate=request.getParameter("isupdate"); if(tno!=null&& tno.trim().length()!=0)
{ try
{
Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "test", "5211314");
if(tbirthday.length()!=0)
{
PreparedStatement pst=conn.prepareStatement(
"insert into TEACHER (tname,tsex,tbirthday,prof,depart,tno)"+
"values(?,?,?,?,?,?)");
if(isupdate!=null&& isupdate.equals("1"))
{ pst = conn.prepareStatement(
"update TEACHER set tname=?,tsex=?,tbirthday=?,prof=?,depart=? where tno=?");
} SimpleDateFormat adf = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date bir= adf.parse(tbirthday); Date sqlBir = new Date(bir.getTime()); pst.setString(6, tno);
pst.setString(1, tname);
pst.setString(2, tsex);
pst.setDate(3, sqlBir);
pst.setString(4, prof);
pst.setString(5, depart);
pst.executeUpdate();
pst.close(); }
else
{
PreparedStatement pst=conn.prepareStatement(
"insert into TEACHER (tname,tsex,prof,depart,tno)"+
"values(?,?,?,?,?)");
if(isupdate!=null&& isupdate.equals("1"))
{ pst = conn.prepareStatement(
"update TEACHER set tname=?,tsex=?,prof=?,depart=? where tno=?");
}
pst.setString(5, tno);
pst.setString(1, tname);
pst.setString(2, tsex);
pst.setString(3, prof);
pst.setString(4, depart);
pst.executeUpdate();
pst.close(); } conn.close(); response.getWriter().write("保存成功");
response.setHeader("refresh", "3;URL=teacherChart.jsp");
} catch (Exception e) { e.printStackTrace();
response.getWriter().write("保存失败");
response.setHeader("refresh", "3;URL=teacherChart.jsp");
} }
else
{
response.getWriter().write("请正确提交数据");
response.setHeader("refresh", "3;URL=teacherChart.jsp");
} } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
} }
package teacher;
import java.sql.*;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; public class DeleteT extends HttpServlet {
private static final long serialVersionUID = 1L; public DeleteT() {
super();
// TODO Auto-generated constructor stub
} protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String tno=request.getParameter("tno");
if(tno!=null&& tno.trim().length()!=0)
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "test", "5211314"); PreparedStatement pst=conn.prepareStatement(
"delete TEACHER where "+"tno=?"); pst.setString(1, tno);
pst.executeUpdate();
pst.close();
conn.close(); response.getWriter().write("删除成功");
response.setHeader("refresh", "3;URL=teacherChart.jsp");
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
response.getWriter().write("删除失败");
response.setHeader("refresh", "3;URL=teacherChart.jsp");
} }
else
{
response.getWriter().write("请正确提交数据");
response.setHeader("refresh", "3;URL=teacherChart.jsp");
}
} protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
} }







对teacher表进行增加,删除,修改的更多相关文章
- AutoCad 二次开发 .net 之层表的增加 删除 修改图层颜色 遍历 设置当前层
AutoCad 二次开发 .net 之层表的增加 删除 修改图层颜色 遍历 设置当前层 AutoCad 二次开发 .net 之层表的增加 删除 修改图层颜色 遍历 设置当前层我理解的图层的作用大概是把 ...
- 在Javascript操作JSON对象,增加 删除 修改
在Javascript操作JSON对象,增加删除修改全有的,详情见代码 <script type="text/javascript"> var jsonObj2 = { ...
- Nodejs之MEAN栈开发(九)---- 用户评论的增加/删除/修改
由于工作中做实时通信的项目,需要用到Nodejs做通讯转接功能,刚开始接触,很多都不懂,于是我和同事就准备去学习nodejs,结合nodejs之MEAN栈实战书籍<Getting.MEAN.wi ...
- [JavaWeb基础] 004.用JSP + SERVLET 进行简单的增加删除修改
上一次的文章,我们讲解了如何用JAVA访问MySql数据库,对数据进行增加删除修改查询.那么这次我们把具体的页面的数据库操作结合在一起,进行一次简单的学生信息操作案例. 首先我们创建一个专门用于学生管 ...
- MySQL使用SQL操作数据表的增加、修改和删除
表的修改和删除 修改 -- 修改表名称 -- ALTER TABLE 旧表名 RENAME AS 新表名 ALTER TABLE test RENAME AS test1 -- 增加表字段 -- AL ...
- Sql增加,删除,修改列
1. 查看约束条件 - MySQL: SELECT * FROM information_schema.`TABLE_CONSTRAINTS` where table_name = 'book'; - ...
- 建表/修改表名/增加删除字段(MySql)
修改表名:alter table 旧表名 rename 新表名; 删除字段:alter table 表名 drop 字段名; 增加字段:alter table 表名 add 字段名 字段类型 [def ...
- 在oracle表中增加、修改、删除字段,表的重命名,字段顺序调整
增加字段语法:alter table tablename add (column datatype [default value][null/not null],….); 说明:alter table ...
- MySQL中的表中增加删除字段
1.增加一个字段alter table user表 add COLUMN new1字段 VARCHAR(20) NOT NULL DEFAULT 0; //增加一个字段,VARCHERA 20 , ...
随机推荐
- LeetCode Add Two Numbers II
原题链接在这里:https://leetcode.com/problems/add-two-numbers-ii/ 题目: You are given two linked lists represe ...
- Eclipse 的单步调试(转)
1.设置断点在程序里面放置一个断点,也就是双击需要放置断点的程序左边的栏目上.2.调试(1)点击"打开透视图"按钮,选择调试透视图,则打开调试透视图界面,然后先设置断点,按调试按钮 ...
- equals == 比较
public class Equals{ public static void main(String[] args){ Interger n1=new Interger(47); Interger ...
- win10本地搭建apache+php+mysql运行环境
首先下载所需软件: Vc2015:https://www.microsoft.com/zh-CN/download/details.aspx?id=48145 Vc2012:http://www.mi ...
- linux查看某个进程内存占用情况以及/proc/pid/status解释
以nginx 为例1.toptop -b -n 1 |grep nginx|awk '{print "VIRT:"$5,"RES:"$6,"cpu:& ...
- Linux selinux iptables
关闭SELINUX – 使用getenforce命令检查SELINUX状态,若结果不是”Disabled”,可使用setenforce 0命令临时关闭SELINUX.要永久关闭SELINUX,需修改/ ...
- WPF绑定xml数据源
1.界面 <UserControl x:Class="HKDCMS.Client.Demo.UIViews.UIControls.AboutUsControl" xmlns= ...
- (三)内存 SDRAM 驱动实验 (杨铸 130 页)(勉强能懂个大概)
SDRAM 芯片讲解: 地址: 行地址 (A0-A12) 列地址 (A0-A8) 片选信号(BA0 BA1)(L-BANK)(因为SDRAM有 4片) 两片SDRAM 连线唯一区别在 UDQM ...
- 关于linux下关于ssd的使用
1. 这几个文件系统可以在挂载的时候使用 discard 选项:ext4, xfs, jfs, vfat 2. 使用 fstrim 命令可以实现周期性的 trim,挂载时使用discard标记可以实 ...
- .net之工作流工程展示及代码分享(四)主控制类
现在应该讲主控制类了,为了不把系统弄得太复杂,所以就用一个类作为主要控制类(服务类),作为前端.后端.业务逻辑的控制类. WorkflowService类的类图如下: 该类的构造函数: public ...