shout_delectdata.java
2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.servlet.bksh.DMC;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.dao.dbutil.DataBase;
public class shout_delectdata extends HttpServlet {
private static final String DB_URL = "db_bk_cxwsjh";
int update = 0;
Connection conn = null;
Statement statement = null;
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String results = request.getParameter("results");
int id = Integer.valueOf(results);
String sql = "DELETE FROM t_shdata_outline WHERE id='" + id + "'";
if (id > 0) {
try {
conn = DataBase.getConnection(DB_URL);
statement = conn.createStatement();
update = statement.executeUpdate(sql);
System.out.print(update);
PrintWriter out = response.getWriter();
if (update == 1) {
out.write("sucess");
} else {
out.write("error");
}
out.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (update == 0) {
System.out.print("库执行失败sql:" + sql);
}
System.out.print("库的sql以及执行结果:" + sql + " is result=" + update);
if (null != conn) {
try {
conn.close();
} catch (Exception e) {
System.out.print("关闭数据库连接出错");
}
}
if (null != statement) {
try {
statement.close();
} catch (Exception e) {
System.out.print("关闭数据库连接出错");
}
}
}
}
}
}