学号 | 姓名 | 语文 | 数学 | 英语 |
---|---|---|---|---|
1001 | 王九 | 0 | 88 | 0 |
4004 | 0 | 0 | 0 | |
4004 | 0 | 0 | 0 | |
1 | 张敏 | 1 | 1 | 1 |
1 | 张三 | 100 | 100 | 100 |
1 | 1 | 100 | 100 | 100 |
90038 | 张三 | 100 | 1001 | 100 |
14 | 周星驰 | 50 | 100 | 80 |
15 | 周惠敏 | 500 | 130 | 1000 |
16 | 张敏 | 600 | 130 | 200 |
17 | 丘淑贞 | 450 | 130 | 1200 |
18 | 舒淇 | 1000 | 2030 | 800 |
20 | 刘德华 | 200 | 1030 | 2000 |
22 | 比尔_盖茨 | 4000 | 5030 | 1000 |
23 | 小布什 | 500 | 530 | 500 |
24 | 毛宁 | 100 | 130 | 100 |
25 | 扬玉莹 | 200 | 230 | 200 |
26 | 巩俐 | 100 | 530 | 1000 |
27 | 李小龙 | 100 | 1030 | 1000 |
28 | 成龙 | 2000 | 1030 | 4000 |
29 | 李连杰 | 250 | 150 | 120 |
30 | 周华键 | 260 | 660 | 560 |
31 | 赵微 | 340 | 1230 | 450 |
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<script type="text/javascript">
function del(){
var msg = "您真的确定要删除吗?\n\n请确认!";
if (confirm(msg)==true){ return true; }
else{ return false; }
}
</script>
<body>
<%
Connection conn;
Statement stmt;
ResultSet rs;
int Page=1;//当前页数
int totalpage=0;//总页数
int totalrecord=0;//总条数
String sql="select * from grade";
String sql1="select count(*) as gradeno from grade";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
System.out.print(e);
}
try{
conn=DriverManager.getConnection("jdbc:odbc:1");
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=stmt.executeQuery(sql1);
rs.next();
totalrecord=rs.getInt(1);
if(totalrecord%5==0){
totalpage=totalrecord/5;
}
else{
totalpage=totalrecord/5+1;
}
rs=stmt.executeQuery(sql);
if(request.getParameter("Page")==null||request.getParameter("Page").equals("")){
Page=1;
}
else{
try{
Page=Integer.parseInt(request.getParameter("Page"));
}
catch(java.lang.NumberFormatException e){
Page=1;
}
}
if(Page>totalpage){
Page=totalpage;
}
if(Page<1){
Page=1;
}
out.print("<table border=1 width=500 align=center>");
rs.absolute((Page-1)*5+1);
for(int i=0;i<5;i++){
String a=rs.getString(1);
out.print("<tr><td><a href=view.jsp?id="+a+">"+a+"</a></td>");
out.print("<td>"+rs.getString(2)+"</td>");
out.print("<td>"+rs.getString(3)+"</td>");
out.print("<td>"+rs.getString(4)+"</td>");
out.print("<td>"+rs.getString(5)+"</td>");
out.print("<td><a href=modify.jsp?id="+a+">修改</a></td>");
out.print("<td><a href=delete.jsp?id="+a+" onClick='javascript:return del();'>删除</a></td></tr>");
if(!rs.next()) break;
}
out.print("<tr><td><a href=index.jsp>第一页</a></td>");
out.print("<td><a href=index.jsp?Page="+(Page-1)+">上一页</a></td>");
out.print("<td><a href=index.jsp?Page="+(Page+1)+">下一页</a></td>");
out.print("<td><a href=index.jsp?Page="+totalpage+">最后一页</a></td></tr>");
conn.close();
}
catch(SQLException e){System.out.print(e);}
%>
<form action="index.jsp" method="post">
当前页:<%=Page%>|<%=totalpage%> 请输入页数:<input type="text" size=2 name="Page"><input type="submit" value="go">
</form>
</body>
</html>
modify.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'modify.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
String id=request.getParameter("id");
String name="";
String yw=null;
String sx=null;
String yy=null;
// out.print(id);
String sql="select * from grade where 学号="+id;
//out.print(sql);
Connection conn;
Statement stmt;
ResultSet rs;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
System.out.print(e);
}
try{
conn=DriverManager.getConnection("jdbc:odbc:1");
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
rs.next();
name=rs.getString(2);
yw=rs.getString(3);
sx=rs.getString(4);
yy=rs.getString(5);
//out.print(name+yw+sx+yy);
conn.close();}
catch(SQLException e){
System.out.print(e);
}
%>
<form action="save.jsp">
请修改学号:<input type="text" name="id" value="<%=id %>" readonly/><br/>
请修改姓名:<input type="text" name="name" value="<%=name%>"/><br/>
请修改语文成绩:<input type="text" name="yw" value="<%=yw %>"/><br/>
请修改数学成绩:<input type="text" name="sx" value="<%=sx %>"/><br/>
请修改英语成绩:<input type="text" name="yy" value="<%=yy %>"/><br/>
<input type="submit" value="修改">
</form>
</body>
</html>
delete.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'delete.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
Connection conn;
Statement stmt;
String id=request.getParameter("id");
String sql="delete from grade where 学号="+id;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
System.out.print(e);
}
try{
conn=DriverManager.getConnection("jdbc:odbc:1");
stmt=conn.createStatement();
int i=stmt.executeUpdate(sql);
out.print("成功删除"+i+"条记录");
conn.close();
}
catch(SQLException e){
System.out.print(e);
}
%>
</body>
</html>
option.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
Connection conn;
Statement stmt;
ResultSet rs;
int n=0;
String a[]=null;
String sql="select count(*) from book";
String sql1="select * from book";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
try{
conn=DriverManager.getConnection("jdbc:odbc:1");
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
rs.next();
n=rs.getInt(1);
// out.print(n);
a=new String[n];
rs=stmt.executeQuery(sql1);
for(int i=0;i<n;i++){
rs.next();
a[i]=rs.getString(3);
//out.print(a[i]);
}
conn.close();
}
catch(SQLException e){
System.out.print(e);
}
%>
<select>
<%
for(int i=0;i<a.length;i++){
%>
<option value="<%=a[i] %>"><%=a[i] %></option>
<%
}
%>
</select>
</body>
</html>
save.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'save.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
request.setCharacterEncoding("gbk");
String id=request.getParameter("id");
String name=new String(request.getParameter("name").getBytes("ISO-8859-1"));
String yw=request.getParameter("yw");
String sx=request.getParameter("sx");
String yy=request.getParameter("yy");
String sql="update grade set 姓名='"+name+"' ,语文="+yw+" ,数学="+sx+", 英语="+yy+" where 学号="+id;
// out.print(sql);
Connection conn;
Statement stmt;
//Result
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
System.out.print(e);
}
try{
conn=DriverManager.getConnection("jdbc:odbc:1");
stmt=conn.createStatement();
int i=stmt.executeUpdate(sql);
out.print("成功修改"+i+"条记录");
conn.close();
}
catch(SQLException e){
System.out.print(e);
}
%>
</body>
</html>
search.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'search.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body><form action="searchrs.jsp" action="post">
请输入检索关键字<input type="text" name="name" size="20">
<input type="submit" value="检索">
</form>
</body>
</html>
searchrs.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'searchrs.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
Connection conn;
Statement stmt;
ResultSet rs;
String name=new String(request.getParameter("name").getBytes("ISO-8859-1"));
String sql="select * from grade where 姓名 like '%"+name+"%'";
// out.print(sql);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
System.out.print(e);
}
try{
conn=DriverManager.getConnection("jdbc:odbc:1");
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
while(rs.next()){
out.print(rs.getString(2)+"<br>");
}
conn.close();
}
catch(SQLException e){System.out.print(e);}
%>
</body>
</html>
view.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'view.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
Connection conn;
Statement stmt;
ResultSet rs;
request.setCharacterEncoding("gbk");
String id=request.getParameter("id");
String sql="select * from grade where 学号="+id;
System.out.print(sql);
out.print(id);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:1");
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
rs.next();
out.print(rs.getString(1)+"<br>");
out.print(rs.getString(2)+"<br>");
out.print(rs.getString(3)+"<br>");
out.print(rs.getString(4)+"<br>");
out.print(rs.getString(5)+"<br>");
conn.close();
%>
</body>
</html>