Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 63cdc7d

Browse files
committed
finished student_jdbc 2016/05/07
1 parent a6700d1 commit 63cdc7d

19 files changed

+246
-55
lines changed

student_jdbc/.classpath

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
<attribute name="owner.project.facets" value="jst.web.jstl"/>
1919
</attributes>
2020
</classpathentry>
21+
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/mysql-connector-java-5.6-bin.jar"/>
2122
<classpathentry kind="output" path="WebRoot/WEB-INF/classes"/>
2223
</classpath>

student_jdbc/.project

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<projectDescription>
3-
<name>student</name>
3+
<name>student_jdbc</name>
44
<comment></comment>
55
<projects>
66
</projects>
@@ -30,6 +30,11 @@
3030
<arguments>
3131
</arguments>
3232
</buildCommand>
33+
<buildCommand>
34+
<name>com.genuitec.eclipse.ast.deploy.core.DeploymentBuilder</name>
35+
<arguments>
36+
</arguments>
37+
</buildCommand>
3338
</buildSpec>
3439
<natures>
3540
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
2-
<wb-module deploy-name="student">
2+
<wb-module deploy-name="student_jdbc">
33
<wb-resource deploy-path="/" source-path="/WebRoot" tag="defaultRootSource"/>
44
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
5-
<property name="context-root" value="student"/>
6-
<property name="java-output-path" value="/student/WebRoot/WEB-INF/classes"/>
5+
<property name="java-output-path" value="/student_jdbc/WebRoot/WEB-INF/classes"/>
6+
<property name="context-root" value="student_jdbc"/>
77
</wb-module>
88
</project-modules>
484 KB
Binary file not shown.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<%@page language="java" import="java.sql.*" pageEncoding="UTF-8" %>
2+
<%request.setCharacterEncoding("UTF-8"); %>
3+
<html>
4+
<head><title>删除一条记录页面</title></head>
5+
<body>
6+
<%
7+
//使用PreparedStatement对象实现数据库记录的修改,其步骤如下:
8+
//(1)建立数据库的连接
9+
String driverName = "com.mysql.jdbc.Driver";
10+
String userName = "root";
11+
String userPwd = "root";
12+
String dbName = "students";
13+
String url1 = "jdbc:mysql://localhost:3306/" + dbName;
14+
String url2 = "?user=" + userName + "&password=" + userPwd;
15+
String url3 = "&useUnicode=true&characterEncoding=UTF-8";
16+
String url = url1 + url2 + url3;
17+
Class.forName(driverName);
18+
Connection conn = DriverManager.getConnection(url);
19+
20+
//(2)形成带参数的修改SQL语句
21+
String sql = "delete from stu_info where weight>=?";
22+
23+
//(3)利用数据库连接对象建立PreparedStatement对象
24+
PreparedStatement pstmt = conn.prepareStatement(sql);
25+
26+
//(4)若是带参数的SQL语句,则对各参数设置相应的参数值
27+
pstmt.setFloat(1, 80);
28+
29+
//(5)调用PreparedStatement对象中的executeUpdate()方法
30+
int n = pstmt.executeUpdate();
31+
//(6)根据executeUpdate()方法的返回值,判断执行结果
32+
if(n==1) {%> 数据删除操作成功!<br><%}
33+
else {%> 数据删除操作失败!<br><%}
34+
35+
//(7)关闭所有资源
36+
if(pstmt != null) pstmt.close();
37+
if(conn != null) conn.close();
38+
%>
39+
</body>
40+
</html>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<%@page contentType="text/html; charset=UTF-8" import="java.sql.*" %>
2+
<html>
3+
<head><title>利用提交条件删除记录页面</title></head>
4+
<body>
5+
<center>
6+
<%
7+
String driverName = "com.mysql.jdbc.Driver";
8+
String userName = "root";
9+
String userPwd = "root";
10+
String dbName = "students";
11+
String url1 = "jdbc:mysql://localhost:3306/" + dbName;
12+
String url2 = "?user=" + userName + "&password=" + userPwd;
13+
String url3 = "&useUnicode=true&characterEncoding=UTF-8";
14+
String url = url1 + url2 + url3;
15+
Class.forName(driverName);
16+
Connection conn = DriverManager.getConnection(url);
17+
18+
request.setCharacterEncoding("UTF-8");
19+
String name = request.getParameter("name");
20+
String sex = request.getParameter("sex");
21+
String ww1 = request.getParameter("w1");
22+
String ww2 = request.getParameter("w2");
23+
String s = "1=1 ";
24+
if(!name.equals("")) s = s + "and name='"+ name + "' ";
25+
if(sex!=null) s = s + "and sex='" + sex + "' ";
26+
double w1,w2;
27+
if(!ww1.equals("")) {
28+
w1 = Double.parseDouble(request.getParameter("w1"));
29+
s = s + "and weight>=" + w1;
30+
}
31+
if(!ww2.equals("")) {
32+
w2 = Double.parseDouble(request.getParameter("w2"));
33+
s = s + " and weight<=" + w2;
34+
}
35+
String sql = "delete from stu_info where " + s;
36+
PreparedStatement pstmt = conn.prepareStatement(sql);
37+
//(5)调用PreparedStatement对象中的executeUpdate()方法
38+
int n = pstmt.executeUpdate();
39+
//(6)根据executeUpdate()方法的返回值,判断执行结果
40+
if(n>=1) {%> 数据修改操作成功!<br><%}
41+
else {%> 数据修改操作失败!<br><%}
42+
43+
//(7)关闭所有资源
44+
if(pstmt != null) pstmt.close();
45+
if(conn != null) conn.close();
46+
%>
47+
</body>
48+
</html>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<%@page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
2+
<%request.setCharacterEncoding("UTF-8"); %>
3+
<html>
4+
<head>
5+
<title>删除条件提交页面</title>
6+
</head>
7+
<body>
8+
请选择删除记录条件
9+
<hr width="100%" size="3">
10+
<form action="delete_stu_2.jsp" method="post">
11+
姓名:<input type="text" name="name"><br> <br> 性别: 男<input
12+
type="radio" value="" name="sex"> 女<input type="radio"
13+
value="" name="sex"><br> <br> 体重范围:
14+
<p>
15+
最小<input type="text" name="w1"> <br> <br>
16+
最大<input type="text" name="w2">
17+
</p>
18+
<input type="submit" value="提 交"> &nbsp;&nbsp;&nbsp;&nbsp; <input
19+
type="reset" value="取 消">
20+
</form>
21+
</body>
22+
</html>

student_jdbc/WebRoot/find_stu_1.jsp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@
66
<body>
77
<center>
88
<%
9+
request.setCharacterEncoding("UTF-8");
910
//使用PreparedStudio对象实现数据库查询,其步骤如下:
1011
//(1)建立数据库的连接
1112
String driverName = "com.mysql.jdbc.Driver";
1213
String userName = "root";
1314
String userPwd = "root";
14-
String dbName = "student";
15+
String dbName = "students";
1516
String url1 = "jdbc:mysql://localhost:3306/" + dbName;
1617
String url2 = "?user=" + userName + "&password=" + userPwd;
1718
String url3 = "&useUnicode=true&characterEncoding=UTF-8";
1819
String url = url1 + url2 + url3;
1920
Class.forName(driverName);
2021
Connection conn = DriverManager.getConnection(url);
2122
//(2)形成查询SQL语句
22-
String sql = "select * from students_info";
23+
String sql = "select * from stu_info";
2324
//(3)利用数据库连接对象建立PreparedStatement对象
2425
PreparedStatement pstmt = conn.prepareStatement(sql);
2526
//调用PreparedStatement的对象的executeQuery()方法,并返回ResultSet对象

student_jdbc/WebRoot/find_stu_2.jsp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<%@page contentType="text/html; charset=UTF-8" import="java.sql.*" %>
2+
<%request.setCharacterEncoding("UTF-8"); %>
23
<html>
34
<head><title>显示体重值在60至80之间的学生</title></head>
45
<body>
@@ -7,15 +8,15 @@
78
String driverName = "com.mysql.jdbc.Driver";
89
String userName = "root";
910
String userPwd = "root";
10-
String dbName = "student";
11+
String dbName = "students";
1112
String url1 = "jdbc:mysql://localhost:3306/" + dbName;
1213
String url2 = "?user=" + userName + "&password=" + userPwd;
1314
String url3 = "&useUnicode=true&characterEncoding=UTF-8";
1415
String url = url1 + url2 + url3;
1516
Class.forName(driverName);
1617
Connection conn = DriverManager.getConnection(url);
1718
//带参数的SQL语句
18-
String sql = "select * from students_info where weight>=? and weight<=?";
19+
String sql = "select * from stu_info where weight>=? and weight<=?";
1920
//不带参数的SQL语句
2021
//String sql = "select * from students_info where weight>=60 and weight<=80";
2122
PreparedStatement pstmt = conn.prepareStatement(sql);

student_jdbc/WebRoot/find_stu_3.jsp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
String driverName = "com.mysql.jdbc.Driver";
88
String userName = "root";
99
String userPwd = "root";
10-
String dbName = "student";
10+
String dbName = "students";
1111
String url1 = "jdbc:mysql://localhost:3306/" + dbName;
1212
String url2 = "?user=" + userName + "&password=" + userPwd;
1313
String url3 = "&useUnicode=true&characterEncoding=UTF-8";
@@ -19,7 +19,7 @@
1919
String sex = request.getParameter("sex");
2020
float weight1 = Float.parseFloat(request.getParameter("w1"));
2121
float weight2 = Float.parseFloat(request.getParameter("w2"));
22-
String sql = "select * from students_info where sex=? and weight>=? and weight<=?";
22+
String sql = "select * from stu_info where sex=? and weight>=? and weight<=?";
2323
PreparedStatement pstmt = conn.prepareStatement(sql);
2424
pstmt.setString(1, sex);
2525
pstmt.setFloat(2, weight1);

0 commit comments

Comments
 (0)