commit
77382aca99
@ -0,0 +1 @@
|
||||
{"data":[1,1,2,3,4,5],"days":["3号","4号","5号","前天","昨天","今天"]}
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,48 +0,0 @@
|
||||
package javabean;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import java.sql.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"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package servlet.admin;
|
||||
|
||||
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 javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import javabean.Base;
|
||||
import javabean.DateTime;
|
||||
import javabean.Util;
|
||||
import net.sf.json.JSONArray;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
@WebServlet("/admin/libraryData")
|
||||
public class LibraryData extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
resp.setContentType("application/json; charset:utf8");
|
||||
// 准备参数
|
||||
Connection connection = null;
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet resultSet = null;
|
||||
String sql = "";
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
JSONArray jsonData = new JSONArray();
|
||||
JSONArray jsonDays = new JSONArray();
|
||||
// 返回参数
|
||||
int code = 1;
|
||||
String msg = "error";
|
||||
int count = 0;
|
||||
PrintWriter out = resp.getWriter();
|
||||
|
||||
// 开始查询
|
||||
try {
|
||||
connection = Base.getConnection();
|
||||
int i = 30;
|
||||
// 获取30天
|
||||
while(i!=0) {
|
||||
i--;
|
||||
sql = "select count(*) as count from borrow_books where date_format(borrow_date,'%Y-%m-%d')=? order by id desc";
|
||||
String date = DateTime.showDate(-i); // 设置日期
|
||||
String md = DateTime.showMD(-i);
|
||||
pstmt = connection.prepareStatement(sql);
|
||||
pstmt.setString(1,date);
|
||||
resultSet = pstmt.executeQuery();
|
||||
while(resultSet.next()) {
|
||||
jsonData.add(resultSet.getString("count"));
|
||||
jsonDays.add(md);
|
||||
}
|
||||
}
|
||||
jsonObject.put("data", jsonData);
|
||||
jsonObject.put("days", jsonDays);
|
||||
if(!jsonObject.isEmpty()) {
|
||||
code = 0;
|
||||
msg = "查询成功";
|
||||
}else {
|
||||
msg = "数据为空";
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
msg = "没找到";
|
||||
e.printStackTrace();
|
||||
} catch (SQLException e) {
|
||||
msg = "sql错误";
|
||||
}finally {
|
||||
try {
|
||||
Base.closeResource(connection, pstmt, resultSet);
|
||||
} catch (SQLException e) {
|
||||
msg = "关闭失败";
|
||||
}
|
||||
}
|
||||
out.print( Util.jsonResponse(code, msg, jsonObject.toString()) );
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue