parent
69373b2e26
commit
9f4aba210b
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,48 @@
|
||||
package javabean;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.mysql.jdbc.Connection;
|
||||
|
||||
public class TestConnection {
|
||||
public static void main(String[] args) throws ClassNotFoundException, SQLException {
|
||||
// 获取rule
|
||||
Connection connection = null;
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet resultSet = null;
|
||||
int result = 0;
|
||||
String password = "1234";
|
||||
String reader = "1234";
|
||||
String rule_id = "1";
|
||||
String status = "1";
|
||||
connection = (Connection) Base.getConnection();
|
||||
String sql = "insert into borrow_card(password, reader, rule_id, status) values(?,?,?,?)";
|
||||
pstmt = connection.prepareStatement(sql);
|
||||
pstmt.setString(1, password);
|
||||
pstmt.setString(2, reader);
|
||||
pstmt.setString(3, rule_id);
|
||||
pstmt.setString(4, status);
|
||||
result = pstmt.executeUpdate();
|
||||
System.out.println(result);
|
||||
//获取id
|
||||
//connection1= (Connection) Base.getConnection();
|
||||
String findIdSql = "select id from borrow_card where password=? and reader=? and rule_id=? and status=? limit 1";
|
||||
pstmt = connection.prepareStatement(findIdSql);
|
||||
pstmt.setString(1, password);
|
||||
pstmt.setString(2, reader);
|
||||
pstmt.setString(3, rule_id);
|
||||
pstmt.setString(4, status);
|
||||
// pstmt1 = connection.prepareStatement(findIdSql);
|
||||
// pstmt1.setString(1, password);
|
||||
// pstmt1.setString(2, reader);
|
||||
// pstmt1.setString(3, rule_id);
|
||||
// pstmt1.setString(4, status);
|
||||
resultSet = pstmt.executeQuery();
|
||||
while(resultSet.next()) {
|
||||
System.out.println(resultSet.getString("id"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* Servlet implementation class ServletExample
|
||||
*/
|
||||
|
||||
public class ServletExample extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ServletExample() {
|
||||
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
response.getWriter().append("Served at: ").append(request.getContextPath());
|
||||
}
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
doGet(request, response);
|
||||
}
|
||||
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* Servlet implementation class Test
|
||||
*/
|
||||
|
||||
public class Test extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* @see HttpServlet#HttpServlet()
|
||||
*/
|
||||
public Test() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
/**
|
||||
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
|
||||
* response)
|
||||
*/
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
// TODO Auto-generated method stub
|
||||
response.getWriter().append("Served at:ddd ").append(request.getContextPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
|
||||
* response)
|
||||
*/
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
// TODO Auto-generated method stub
|
||||
doGet(request, response);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package servlet.admin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.mysql.jdbc.Connection;
|
||||
|
||||
import javabean.Base;
|
||||
import net.sf.json.JSONArray;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
@WebServlet("/admin/cardDel")
|
||||
public class CardDel extends HttpServlet {
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
resp.setContentType("application/json; charset=utf8");
|
||||
// 接收数据
|
||||
String id = req.getParameter("id");
|
||||
// 处理数据
|
||||
Connection connection = null;
|
||||
PreparedStatement delCardPstmt = null;
|
||||
PreparedStatement delHistoryPstmt = null;
|
||||
String delCardSql = null;
|
||||
String delHistorySql = null;
|
||||
int delCardResult = 0;
|
||||
int delHistoryResult = 0;
|
||||
// 返回数据
|
||||
String code = "1";
|
||||
String msg = "error";
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
JSONObject jsonData = new JSONObject();
|
||||
// 开始处理
|
||||
if(id != null && !id.equals("")) {
|
||||
try {
|
||||
// 公共连接
|
||||
connection = (Connection) Base.getConnection();
|
||||
// 删除借书记录
|
||||
delHistorySql = "delete from borrow_books where card_id=?";
|
||||
delHistoryPstmt = connection.prepareStatement(delHistorySql);
|
||||
delHistoryPstmt.setString(1, id);
|
||||
delHistoryResult = delHistoryPstmt.executeUpdate();
|
||||
// 返回删除记录条数
|
||||
jsonData.put("num", delHistoryResult);
|
||||
// 删除阅读证
|
||||
delCardSql = "delete from borrow_card where id=? limit 1";
|
||||
delCardPstmt = connection.prepareStatement(delCardSql);
|
||||
delCardPstmt.setString(1, id);
|
||||
delCardResult = delCardPstmt.executeUpdate();
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
msg = "连接失败";
|
||||
} catch (SQLException e) {
|
||||
msg = "sql错误";
|
||||
} finally {
|
||||
try {
|
||||
delCardPstmt.close();
|
||||
Base.closeResource(connection, delCardPstmt, null);
|
||||
} catch (SQLException e) {
|
||||
msg = "关闭失败";
|
||||
}
|
||||
}
|
||||
}
|
||||
PrintWriter out = resp.getWriter();
|
||||
if(delCardResult == 1) {
|
||||
code = "0";
|
||||
msg = "删除借阅证成功";
|
||||
}
|
||||
jsonObject.put("code", code);
|
||||
jsonObject.put("msg", msg);
|
||||
jsonObject.put("data", jsonData);
|
||||
out.print(jsonObject.toString());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
package servlet.admin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.mysql.jdbc.Connection;
|
||||
|
||||
import javabean.Base;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
|
||||
@WebServlet("/admin/cardEdit")
|
||||
public class CardEdit extends HttpServlet {
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
resp.setContentType("application/json; charset=utf8");
|
||||
// 接受数据
|
||||
String id = req.getParameter("id");
|
||||
String password = req.getParameter("password");
|
||||
String reader = req.getParameter("reader");
|
||||
String rule_id = req.getParameter("rule_id");
|
||||
String status = req.getParameter("status");
|
||||
// 准备资源
|
||||
Connection connection = null;
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet resultSet = null;
|
||||
int result = 0;
|
||||
String sql = null;
|
||||
// 返回数据
|
||||
String code = "1";
|
||||
String msg = "error";
|
||||
JSONObject json = new JSONObject();
|
||||
PrintWriter out = resp.getWriter();
|
||||
// 判断数据
|
||||
if(id == null || password == null || reader == null || reader == null || status == null ||
|
||||
id.equals("") || password.equals("") || reader.equals("") || rule_id.equals("") || status.equals("")) {
|
||||
code = "1";
|
||||
msg = "参数不能为空";
|
||||
}else {
|
||||
sql = "update borrow_card set password=?, reader=?, rule_id=?, status=? where id=?";
|
||||
try {
|
||||
connection = (Connection) Base.getConnection();
|
||||
pstmt = connection.prepareStatement(sql);
|
||||
pstmt.setString(1, password);
|
||||
pstmt.setString(2, reader);
|
||||
pstmt.setString(3, rule_id);
|
||||
pstmt.setString(4, status);
|
||||
pstmt.setString(5, id);
|
||||
result = pstmt.executeUpdate();
|
||||
} catch (ClassNotFoundException e1) {
|
||||
msg = "错误";
|
||||
} catch (SQLException e) {
|
||||
msg = "sql错误";
|
||||
} finally {
|
||||
try {
|
||||
Base.closeResource(connection, pstmt, resultSet);
|
||||
} catch (SQLException e) {
|
||||
msg = "关闭失败";
|
||||
}
|
||||
}
|
||||
if(result == 1) {
|
||||
code = "0";
|
||||
msg = "修改成功";
|
||||
}
|
||||
json.put("code", code);
|
||||
json.put("msg", msg);
|
||||
out.print(json.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue