azure011328

导航

 
1.数据库连接类
1 package com.wang.utils;
 2 
 3 import java.sql.Connection;
 4 import java.sql.DriverManager;
 5 import java.sql.ResultSet;
 6 import java.sql.SQLException;
 7 import java.sql.Statement;
 8 
 9 public class DBUtils {
10                                                               //数据库名
11     public static String db_url = "jdbc:mysql://localhost:3306/wang?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT";
12     public static String db_user = "root";   //用户名
13     public static String db_password = "123456"; //密码
14      
15     public static Connection getConn () {
16         Connection conn = null;
17         try {
18             Class.forName("com.mysql.cj.jdbc.Driver");//加载驱动
19             conn = DriverManager.getConnection(db_url, db_user, db_password);//获取连接对象
20         } catch (Exception e) {
21             e.printStackTrace();
22         }
23         return conn;
24     }
25      
26     /**
27      * 关闭连接
28      * @param state
29      * @param conn
30      */
31     public static void close (Statement state, Connection conn) {
32         if (state != null) {
33             try {
34                 state.close();
35             } catch (SQLException e) {
36                 e.printStackTrace();
37             }
38         }
39         if (conn != null) {
40             try {
41                 conn.close();
42             } catch (SQLException e) {
43                 e.printStackTrace();
44             }
45         }
46     }
47      
48     /**
49      * 关闭连接
50      * @param rs
51      * @param state
52      * @param conn
53      */
54     public static void close (ResultSet rs, Statement state, Connection conn) {
55         if (rs != null) {
56             try {
57                 rs.close();
58             } catch (SQLException e) {
59                 e.printStackTrace();
60             }
61         }
62         if (state != null) {
63             try {
64                 state.close();
65             } catch (SQLException e) {
66                 e.printStackTrace();
67             }
68         }
69         if (conn != null) {
70             try {
71                 conn.close();
72             } catch (SQLException e) {
73                 e.printStackTrace();
74             }
75         }
76     }
77  
78 }

DBUtils.java

  2.实体类

1 package com.wang.pojo;
 2 
 3 import java.math.BigDecimal;
 4 
 5 public class HomeCost {
 6     
 7     private int id;//id
 8     private String name;//消费名称
 9     private BigDecimal money;//消费金额
10     private String date;//消费日期
11     private BigDecimal sum;//累计消费
12     
13     
14     public int getId() {
15         return id;
16     }
17     public void setId(int id) {
18         this.id = id;
19     }
20     public String getName() {
21         return name;
22     }
23     public void setName(String name) {
24         this.name = name;
25     }
26     public BigDecimal getMoney() {
27         return money;
28     }
29     public void setMoney(BigDecimal money) {
30         this.money = money;
31     }
32     public String getDate() {
33         return date;
34     }
35     public void setDate(String date) {
36         this.date = date;
37     }
38     public BigDecimal getSum() {
39         return sum;
40     }
41     public void setSum(BigDecimal sum) {
42         this.sum = sum;
43     }
44     
45     
46        
47     @Override
48     public String toString() {
49         return "HomeCost [id=" + id + ", name=" + name + ", money=" + money + ", date=" + date + ", sum=" + sum + "]";
50     }
51     
52     public HomeCost() {}
53     
54     public HomeCost(String name, BigDecimal money) {
55         super();
56         this.name = name;
57         this.money = money;
58     }
59     
60     public HomeCost(int id,String name,BigDecimal money, String date) {
61         super();
62         this.id=id;
63         this.name = name;
64         this.money=money;
65         this.date=date;
66     }
67     public HomeCost(int id, String name, BigDecimal money, String date, BigDecimal sum) {
68         super();
69         this.id = id;
70         this.name = name;
71         this.money = money;
72         this.date = date;
73         this.sum = sum;
74     }
75     
76 }

HomeCost.java

 

posted on 2024-01-27 15:12  淮竹i  阅读(17)  评论(0)    收藏  举报