一丶基本机构
数据库截图
record表
年份表
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>记账本主页</title> </head> <body> <h1>小神龙的记账本</h1> <div align="center"> <div class="a"> <a href="one.jsp">记一笔</a> </div> <div class="a"> <a href="all.jsp">查看所有消费记录</a> </div> <div class="a"> <a href="monthsee.jsp">按年份月份查询消费记录</a> </div> <div class="a"> <a href="choose.jsp">按分类查询消费报表</a> </div> </div> </body> </html>
one.jsp记一笔记账功能
<%@page import="java.util.Date"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.util.*" %> <%@page import="java.text.SimpleDateFormat"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <form action="One" method="post"> <% Date d = new Date(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String now = df.format(d); %> <table align="center" width="450"> <tr> <td align="center" colspan="2"> <h1>添加一笔记录</h1> <hr /> </td> </tr> <tr> <td align="right">金额</td> <td> <input type="text" name="money" > </td> </tr> <tr> <td align="right">日期</td> <td> <input type="text" name="date" value=<%=now %>> </td> </tr> <tr> <td align="right">备注</td> <td> <input type="text" name="beizhu"> </td> </tr> <tr> <td align="right">选择分类</td> <td> <select name="fenlei"> <option value="-1">---请选择---</option> <option value="0">餐饮</option> <option value="1">娱乐</option> <option value="2">旅游</option> <option value="3">其他</option> </select> </td> </tr> <tr> <td align="right">选择支出或收入</td> <td> <input type="radio" name="zz" value="1" />支出 <input type="radio" name="zz" value="0" />收入</td> </tr> <tr> <td align="center" colspan="2"> <input type="submit" value="提 交" /> </td> </tr> </table> </form> </body> </html>
all.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.util.*" %> <%@ page import="java.sql.Date" %> <%@ page import="Dao.Dao" %> <%@ page import="Basis.record" %> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>所有记录信息</title> <style type="text/css"> td { font-size: 12px; } h2 { margin: 0px } </style> <script type="text/javascript"> </script> <style type="text/css"> body{ 100%; height: 100%; margin: 20; background: #00FFCC url(image/2.jpg); } </style> </head> <body> <form action=""method="post"> <table align="center" width="700" border="10" height="250" bordercolor="white" bgcolor="black" cellpadding="1" cellspacing="1"> <tr bgcolor="white"> <td align="center" colspan="15"> <h2>所有记录信息</h2> </td> </tr> <tr align="center" bgcolor="#e1ffc1"> <td><b>编号</b></td> <td><b>分类</b></td> <td><b>日期</b></td> <td><b>金额</b></td> <td><b>备注</b></td> </tr> <% Dao dao=new Dao(); List<record> list=dao.getall(); // 判断是否有数据 if (list == null ) { %> <tr bgcolor="white"><td colspan="15" ><h4 align="center">没有数据</h4></td></tr> <% } else { for (record r : list) { %> <tr align="center" bgcolor="white"> <td><%=r.getId()%></td> <td><%=r.getFenlei()%></td> <td><%=r.getDate()%></td> <td><%=r.getMoney()%></td> <td><%=r.getBeizhu()%></td> </tr> <% } } %> </table> <div class="a" align="center"> <a href="index.jsp">返 回 主 页</a> </div> </form> </body> </html>
choose.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.util.*" %> <%@ page import="java.sql.Date" %> <%@ page import="Dao.Dao" %> <%@ page import="Basis.record" %> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style type="text/css"> td { font-size: 12px; } h2 { margin: 0px } </style> <script type="text/javascript"> </script> <style type="text/css"> body{ 100%; height: 100%; margin: 20; background: #00FFCC url(image/2.jpg); } </style> </head> <body> <form action="Choose" method="post"> <table align="center" width="700" border="10" height="250" bordercolor="white" bgcolor="black" cellpadding="1" cellspacing="1"> <tr bgcolor="white"> <td align="center" colspan="15"> <h2>查询记录信息</h2> </td> </tr> <tr bgcolor="white"> <td align="right">输入年份</td> <td> <input type="text" name="year" > </td> <td align="right">选择月份</td> <td> <select name="month"> <option value="0">---请选择---</option> <option value="1">一月</option> <option value="2">二月</option> <option value="3">三月</option> <option value="4">四月</option> <option value="5">五月</option> <option value="6">六月</option> <option value="7">七月</option> <option value="8">八月</option> <option value="9">九月</option> <option value="10">十月</option> <option value="11">十一月</option> <option value="12">十二月</option> </select> </td> <td align="right">选择分类</td> <td> <select name="fenlei"> <option value="-1">---请选择---</option> <option value="0">餐饮</option> <option value="1">娱乐</option> <option value="2">旅游</option> <option value="3">其他</option> </select> </td> <td> <input type="submit" value="查 询" /> </td> </tr> </table> </form> </body> </html>
choosesee.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.util.*" %> <%@ page import="java.sql.Date" %> <%@ page import="Dao.Dao" %> <%@ page import="Basis.record" %> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>所有记录信息</title> <style type="text/css"> td { font-size: 12px; } h2 { margin: 0px } </style> <script type="text/javascript"> </script> <style type="text/css"> body{ 100%; height: 100%; margin: 20; background: #00FFCC url(image/2.jpg); } </style> </head> <body> <form action="Chaxun" method="post"> <table align="center" width="700" border="10" height="250" bordercolor="white" bgcolor="black" cellpadding="1" cellspacing="1"> <tr bgcolor="white"> <td align="center" colspan="15"> <h2>所有记录信息</h2> </td> </tr> <tr align="center" bgcolor="#e1ffc1"> <td><b>编号</b></td> <td><b>分类</b></td> <td><b>日期</b></td> <td><b>金额</b></td> <td><b>备注</b></td> </tr> <% List<record> list=(List<record>)session.getAttribute("ss"); // 判断是否有数据 if (list == null ) { %> <tr bgcolor="white"><td colspan="15" ><h4 align="center">没有数据</h4></td></tr> <% } else { for (record r : list) { %> <tr align="center" bgcolor="white"> <td><%=r.getId()%></td> <td><%=r.getFenlei()%></td> <td><%=r.getDate()%></td> <td><%=r.getMoney()%></td> <td><%=r.getBeizhu()%></td> </tr> <% } } %> </table> <div class="a" align="center"> <a href="index.jsp">返 回 主 页</a> </div> </form> </body> </html>
fff.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.util.*" %> <%@ page import="java.sql.Date" %> <%@ page import="Dao.Dao" %> <%@ page import="Basis.record" %> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>所有记录信息</title> <style type="text/css"> td { font-size: 12px; } h2 { margin: 0px } </style> <script type="text/javascript"> </script> <style type="text/css"> body{ 100%; height: 100%; margin: 20; background: #00FFCC url(image/2.jpg); } </style> </head> <body> <form action="Chaxun" method="post"> <table align="center" width="700" border="10" height="250" bordercolor="white" bgcolor="black" cellpadding="1" cellspacing="1"> <tr bgcolor="white"> <td align="center" colspan="15"> <h2>所有记录信息</h2> </td> </tr> <tr bgcolor="white"> <td align="right">输入年份</td> <td> <input type="text" name="year" > </td> <td align="right">选择月份</td> <td> <select name="month"> <option value="0">---请选择---</option> <option value="1">一月</option> <option value="2">二月</option> <option value="3">三月</option> <option value="4">四月</option> <option value="5">五月</option> <option value="6">六月</option> <option value="7">七月</option> <option value="8">八月</option> <option value="9">九月</option> <option value="10">十月</option> <option value="11">十一月</option> <option value="12">十二月</option> </select> </td> <td> <input type="submit" value="查 询" /> </td> </tr> <tr align="center" bgcolor="#e1ffc1"> <td><b>编号</b></td> <td><b>分类</b></td> <td><b>日期</b></td> <td><b>金额</b></td> <td><b>备注</b></td> </tr> <% List<record> list=(List<record>)session.getAttribute("ss"); // 判断是否有数据 if (list == null ) { %> <tr bgcolor="white"><td colspan="15" ><h4 align="center">没有数据</h4></td></tr> <% } else { for (record r : list) { %> <tr align="center" bgcolor="white"> <td><%=r.getId()%></td> <td><%=r.getFenlei()%></td> <td><%=r.getDate()%></td> <td><%=r.getMoney()%></td> <td><%=r.getBeizhu()%></td> </tr> <% } } %> </table> <div class="a" align="center"> <a href="index.jsp">返 回 主 页</a> </div> </form> </body> </html>
monthsee.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.util.*" %> <%@ page import="java.sql.Date" %> <%@ page import="Dao.Dao" %> <%@ page import="Basis.record" %> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>所有记录信息</title> <style type="text/css"> td { font-size: 12px; } h2 { margin: 0px } </style> <script type="text/javascript"> </script> <style type="text/css"> body{ 100%; height: 100%; margin: 20; background: #00FFCC url(image/2.jpg); } </style> </head> <body> <form action="Chaxun" method="post"> <table align="center" width="700" border="10" height="250" bordercolor="white" bgcolor="black" cellpadding="1" cellspacing="1"> <tr bgcolor="white"> <td align="center" colspan="15"> <h2>所有记录信息</h2> </td> </tr> <tr bgcolor="white"> <td align="right">输入年份</td> <td> <input type="text" name="year" > </td> <td align="right">选择月份</td> <td> <select name="month"> <option value="0">---请选择---</option> <option value="1">一月</option> <option value="2">二月</option> <option value="3">三月</option> <option value="4">四月</option> <option value="5">五月</option> <option value="6">六月</option> <option value="7">七月</option> <option value="8">八月</option> <option value="9">九月</option> <option value="10">十月</option> <option value="11">十一月</option> <option value="12">十二月</option> </select> </td> <td> <input type="submit" value="查 询" /> </td> </tr> <tr align="center" bgcolor="#e1ffc1"> <td><b>编号</b></td> <td><b>分类</b></td> <td><b>日期</b></td> <td><b>金额</b></td> <td><b>备注</b></td> </tr> <% Dao dao=new Dao(); List<record> list=dao.getall(); if((List<record>)session.getAttribute("ss")!=null){ list = (List<record>)session.getAttribute("ss"); } // 判断是否有数据 if (list == null ) { %> <tr bgcolor="white"><td colspan="15" ><h4 align="center">没有数据</h4></td></tr> <% } else { for (record r : list) { %> <tr align="center" bgcolor="white"> <td><%=r.getId()%></td> <td><%=r.getFenlei()%></td> <td><%=r.getDate()%></td> <td><%=r.getMoney()%></td> <td><%=r.getBeizhu()%></td> </tr> <% } } %> </table> <div class="a" align="center"> <a href="index.jsp">返 回 主 页</a> </div> </form> </body> </html>
success.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <h3>5秒后自动跳转</h3> <script language="javascript"> var times=6; clock(); function clock() { window.setTimeout('clock()',1000); times=times-1; time.innerHTML =times; } </script> <head> <meta http-equiv= "Refresh" content= "5;url=index.jsp "> </head> <body> <div id= "time"> 5 </div> <div class="a"> <a href="index.jsp">或者点击此处直接跳转</a> </div> </body> </html>
Chaxun.java
package Servlet; import java.io.IOException; import java.sql.Date; import java.util.List; 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 javax.servlet.http.HttpSession; import Basis.record; import Dao.Dao; /** * Servlet implementation class Chaxun */ @WebServlet("/Chaxun") public class Chaxun extends HttpServlet { private static final long serialVersionUID = 1L; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request, response); } protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String year=req.getParameter("year"); String month=req.getParameter("month"); if(month.equals("一月")) { month="01"; } else if(month.equals("二月")) { month="02"; } else if(month.equals("三月")) { month="03"; } else if(month.equals("四月")) { month="04"; } else if(month.equals("五月")) { month="05"; } else if(month.equals("六月")) { month="06"; } else if(month.equals("七月")) { month="07"; } else if(month.equals("八月")) { month="08"; } else if(month.equals("九月")) { month="09"; } else if(month.equals("十月")) { month="10"; } else if(month.equals("十一月")) { month="11"; } else if(month.equals("十二月")) { month="12"; } System.out.println(year+month); java.sql.Date sDate = new java.sql.Date(Integer.parseInt(year)-1900, Integer.parseInt(month)-1, 1); java.sql.Date bDate = new java.sql.Date(Integer.parseInt(year)-1900, Integer.parseInt(month)-1, 31); System.out.println(sDate); //Date date=Dao.enqueryDate(); Dao dao = new Dao(); HttpSession session=req.getSession(); List<record> sList = dao.name(sDate,bDate); session.setAttribute("ss", sList); req.getRequestDispatcher("fff.jsp").forward(req,resp); } }
Choose.java
package Servlet; import java.io.IOException; import java.util.List; 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 javax.servlet.http.HttpSession; import Basis.record; import Dao.Dao; /** * Servlet implementation class servlet */ @WebServlet("/Choose") public class Choose extends HttpServlet { private static final long serialVersionUID = 1L; protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String year=req.getParameter("year"); String month=req.getParameter("month"); String fenlei=req.getParameter("fenlei"); System.out.println("你好"); if(month.equals("一月")) { month="01"; } else if(month.equals("二月")) { month="02"; } else if(month.equals("三月")) { month="03"; } else if(month.equals("四月")) { month="04"; } else if(month.equals("五月")) { month="05"; } else if(month.equals("六月")) { month="06"; } else if(month.equals("七月")) { month="07"; } else if(month.equals("八月")) { month="08"; } else if(month.equals("九月")) { month="09"; } else if(month.equals("十月")) { month="10"; } else if(month.equals("十一月")) { month="11"; } else if(month.equals("十二月")) { month="12"; } if(fenlei.equals("0")) { fenlei="餐饮"; } else if(fenlei.equals("1")) { fenlei="娱乐"; } else if(fenlei.equals("2")) { fenlei="旅游"; } else if(fenlei.equals("3")) { fenlei="其他"; } java.sql.Date sDate = new java.sql.Date(Integer.parseInt(year)-1900, Integer.parseInt(month)-1, 1); java.sql.Date bDate = new java.sql.Date(Integer.parseInt(year)-1900, Integer.parseInt(month)-1, 31); Dao dao = new Dao(); HttpSession session=req.getSession(); List<record> List = dao.chaxun(sDate,bDate,fenlei); session.setAttribute("ss", List); req.getRequestDispatcher("choosesee.jsp").forward(req,resp); } }
One.java
package Servlet; import java.io.IOException; import java.sql.Date; 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 javax.servlet.http.HttpSession; import Basis.record; import Basis.y2019; import Connection.MyUTF; import Dao.Dao; /** * Servlet implementation class One */ @WebServlet("/One") public class One extends HttpServlet { public static String dateToString(java.sql.Date sqlDate) { return sqlDate.toString(); } private static final long serialVersionUID = 1L; protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String money=req.getParameter("money"); java.util.Date utilDate = new java.util.Date(); System.out.println("utilDate : " + utilDate); //util.Date转sql.Date java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); System.out.println("sqlDate:"+sqlDate); //sqldate转换为string String sdate = dateToString(sqlDate); //分割stringdate String[] qq=sdate.split("-"); System.out.println(qq[0]); String beizhu=req.getParameter("beizhu"); String fenlei=req.getParameter("fenlei"); String zz=req.getParameter("zz"); beizhu = MyUTF.getNewString(beizhu); if(fenlei.equals("0")) { fenlei="餐饮"; } else if(fenlei.equals("1")) { fenlei="娱乐"; } else if(fenlei.equals("2")) { fenlei="旅游"; } else if(fenlei.equals("3")) { fenlei="其他"; } System.out.println(fenlei); Dao dao=new Dao(); //支入或支出 if(zz.equals("1")) { money="-"+money; } else if(zz.equals("0")) { money=money; } dao.add(money,sqlDate,beizhu,fenlei); try { y2019 y = dao.zhodaotamen(qq[0], qq[1]); int ot = 0; if(fenlei.equals("餐饮")) { fenlei="food"; System.out.println(y.getFood()); ot = Integer.parseInt(y.getFood()); } else if(fenlei.equals("娱乐")) { fenlei="play"; ot = Integer.parseInt(y.getPlay()); } else if(fenlei.equals("旅游")) { fenlei="go"; ot = Integer.parseInt(y.getGo()); } else if(fenlei.equals("其他")) { fenlei="other"; ot = Integer.parseInt(y.getOther()); } System.out.println("fenlei"+fenlei); int mo = Integer.parseInt(money); System.out.println("ot "+ot); int moO = ot+(int)mo; int moA = mo+Integer.parseInt(y.getMoney()); dao.genxin(qq[0],fenlei, moA+"", qq[1], ""+moO); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } /* * if(qq[0]=="2019") { if(fenlei.equals("餐饮")) { dao.enqueryfood(fenlei,qq[]) * dao.addfood(fenlei,qq[1]); } else if(fenlei.equals("娱乐")) { * * } else if(fenlei.equals("旅游")) { * * } else if(fenlei.equals("其他")) { * * } } else if(qq[0]=="2018") { * * } else if(qq[0]=="2018") { * * } */ req.getRequestDispatcher("success.jsp").forward(req,resp); } }
Dao.java
package Dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.*; import Basis.record; import Basis.y2019; import Connection.connection; import Dao.Dao; public class Dao { static Connection getconn() { Connection conn = connection.getConnection(); return conn; } public List<record> chaxun(java.sql.Date sDate, java.sql.Date bDate, String fenlei) { String sql="select * from record where date BETWEEN '"+sDate+"' and '"+bDate+"'and fenlei ='"+fenlei+"'"; System.out.println(sql); Connection conn =Dao.getconn(); List<record> list=new ArrayList<record>(); try { PreparedStatement pst=conn.prepareStatement(sql); ResultSet rst=pst.executeQuery(); while(rst.next()) { record r=new record(); r.setId(rst.getInt("id")); r.setDate(rst.getDate("date")); r.setMoney(rst.getString("money")); r.setFenlei(rst.getString("fenlei")); r.setBeizhu(rst.getString("beizhu")); list.add(r); } } catch (Exception e) { e.printStackTrace(); } return list; } public List<record> name(java.sql.Date sDate , java.sql.Date pDate) { String sql = "select * from record where date BETWEEN '"+sDate+"' and ' "+pDate+"'"; System.out.println(sql); Connection conn =Dao.getconn(); List<record> list=new ArrayList<record>(); try { PreparedStatement pst=conn.prepareStatement(sql); ResultSet rst=pst.executeQuery(); while(rst.next()) { record r=new record(); r.setId(rst.getInt("id")); r.setDate(rst.getDate("date")); r.setMoney(rst.getString("money")); r.setFenlei(rst.getString("fenlei")); r.setBeizhu(rst.getString("beizhu")); list.add(r); } } catch (Exception e) { e.printStackTrace(); } return list; } public boolean add(String money, Date date, String beizhu, String fenlei) { // 添加一笔数据 Connection conn =Dao.getconn(); String sql = "insert into record (money,date,beizhu,fenlei) values ('"+money+"','"+date+"','"+beizhu+"','"+fenlei+"')"; System.out.println(sql); Statement state = null; try { state = conn.createStatement(); int a = state.executeUpdate(sql); return a > 0 ? true : false; } catch (Exception e) { e.printStackTrace(); } return false; } public List<record> getall(){ //得到所有单据记录 List<record> list=new ArrayList<record>(); Connection conn =Dao.getconn(); String sql="select * from record"; try { PreparedStatement pst=conn.prepareStatement(sql); ResultSet rst=pst.executeQuery(); while(rst.next()) { record r=new record(); r.setId(rst.getInt("id")); r.setDate(rst.getDate("date")); r.setMoney(rst.getString("money")); r.setFenlei(rst.getString("fenlei")); r.setBeizhu(rst.getString("beizhu")); list.add(r); } rst.close(); pst.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return list; } public void addfood(String fenlei, String month) { // 添加食物消费 String sql="insert into 2019"; } public y2019 zhodaotamen(String year,String month) throws SQLException { String sql = "select * from `"+year+"` where month ='"+month+"'"; System.out.println("sql"+sql); Connection conn =Dao.getconn(); PreparedStatement pst=conn.prepareStatement(sql); ResultSet rst=pst.executeQuery(); y2019 mianpi=new y2019(); while(rst.next()) { mianpi.setFood(rst.getString("food")); mianpi.setMonth(rst.getString("month")); mianpi.setPlay(rst.getString("play")); mianpi.setGo(rst.getString("go")); mianpi.setOther(rst.getString("other")); mianpi.setMoney(rst.getString("money")); } System.out.println("root "+mianpi.getFood()); return mianpi; } public void genxin(String nian,String fenlei,String mo,String month,String ot) { String sql = "UPDATE `"+nian+"` SET "+fenlei+"= '"+ot+"',money = '"+mo+"' WHERE month = '"+month+"'"; System.out.println(sql); Connection conn = Dao.getconn(); try { Statement stmt=(Statement) conn.createStatement(); int asd = stmt.executeUpdate(sql); System.out.println("genxing "+asd); } catch (SQLException e) { e.printStackTrace(); } finally { } } }
record.java
package Basis; import java.sql.Date; public class record { private int id; private String fenlei; private Date date; private String money; private String beizhu; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getFenlei() { return fenlei; } public void setFenlei(String fenlei) { this.fenlei = fenlei; } public Date getDate() { return date; } public void setDate(Date date) { this.date = date; } public String getMoney() { return money; } public void setMoney(String money) { this.money = money; } public String getBeizhu() { return beizhu; } public void setBeizhu(String beizhu) { this.beizhu = beizhu; } }
y2019.java
package Basis; public class y2019 { private String month; private String food; private String play; private String go; private String other; private String money; public String getMonth() { return month; } public void setMonth(String month) { this.month = month; } public String getFood() { return food; } public void setFood(String food) { this.food = food; } public String getPlay() { return play; } public void setPlay(String play) { this.play = play; } public String getGo() { return go; } public void setGo(String go) { this.go = go; } public String getOther() { return other; } public void setOther(String other) { this.other = other; } public String getMoney() { return money; } public void setMoney(String money) { this.money = money; } }
connection.java
package Connection; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class connection { private static String url = "jdbc:mysql://localhost:3306/jizhangben?useSSL=false&serverTimezone=UTC&characterEncoding=utf-8"; private static String userName = "root"; // private static String passWord = "xcl123"; // private static Connection conn = null; @SuppressWarnings("unused") private void DbHelper() { } public static Connection getConnection() { if(conn==null) { try { Class.forName("com.mysql.cj.jdbc.Driver"); conn=DriverManager.getConnection(url, userName, passWord); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return conn; } public static void close (Statement state, Connection conn) { if (state != null) { try { state.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } public static void close (ResultSet rs, Statement state, Connection conn) { if (rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if (state != null) { try { state.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } public static void main(String[] args) throws SQLException { Connection conn=getConnection(); PreparedStatement pstmt=null; ResultSet rs=null; String sql="select*from user"; pstmt=conn.prepareStatement(sql); rs=pstmt.executeQuery(); if(rs.next()) { System.out.println("有"); } else { System.out.println("无"); } } }
MyUTF.java
package Connection; import java.io.UnsupportedEncodingException; public class MyUTF { //封装成工具类 public static String getNewString(String str) throws UnsupportedEncodingException { return new String(str.getBytes("ISO-8859-1"),"UTF-8"); } }
功能展示
添加一笔信息
查看所有消费记录
按年份月份查询消费记录
查询结果
按分类查询消费报表