wuyouming666
2023-11-30 8dfb37b10ffb2fcb41c85b3fa266d1ef2874aebc
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package com.example.springboot.service;
 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
 
import org.springframework.stereotype.Component;
 
import com.example.springboot.entity.Glass;
import com.example.springboot.entity.north_glass_buffer1;
@Component
public class JdbcConnections {
    /**
     * 数据库连接参数
     * driver,url,username,password
     */
    private static final String DRIVER = "com.mysql.jdbc.Driver";
    private static final String URL = "jdbc:mysql://localhost:3306/canadames";
    private static final String USERNAME = "root";
    private static final String PASSWORD = "beibo.123/";
    
    private static Connection conn = null;
    private static PreparedStatement ps = null;
    private static ResultSet rs = null;
    
    public  north_glass_buffer1 selectGlass(int glassid) throws SQLException {
        conn = getConn();
        north_glass_buffer1 glass=new north_glass_buffer1();
        String sql = "select ordernumber from north_glass_buffer1 where glassid=?";
         ps = conn.prepareStatement(sql);
         ps.setInt(1, glassid);
         rs= ps.executeQuery();
         while (rs.next()) {
            glass.setordernumber(rs.getString("ordernumber"));
         }
         conn.close();
         return glass;
    }
 
    public  north_glass_buffer1 SelectGlassByGlassIdOrderIdFrameId(String glassid,String orderid,String frameid) throws SQLException {
        conn = getConn();
        north_glass_buffer1 north_glass_buffer1s=new north_glass_buffer1();
        String sql = "select * from north_glass_buffer1 where barcode=? or ordernumber=? or FrameBarcode=?";
         ps = conn.prepareStatement(sql);
         ps.setString(1, glassid);
         ps.setString(2, orderid);
         ps.setString(3, frameid);
         rs= ps.executeQuery();
         while (rs.next()) {
            north_glass_buffer1s.setId(rs.getInt("Id"));
            north_glass_buffer1s.setordernumber(rs.getString("ordernumber"));
            north_glass_buffer1s.setlistnumber(rs.getString("listnumber"));
            north_glass_buffer1s.setboxnumber(rs.getString("boxnumber"));
            north_glass_buffer1s.setbarcode(rs.getString("barcode"));
            north_glass_buffer1s.setglasslength(rs.getDouble("glasslength"));
            north_glass_buffer1s.setglassheight(rs.getDouble("glassheight"));
            north_glass_buffer1s.setglasslengthmm(rs.getDouble("glasslength_mm"));
            north_glass_buffer1s.setglassheightmm(rs.getDouble("glassheight_mm"));
            north_glass_buffer1s.setitemtype(rs.getString("itemtype"));
            north_glass_buffer1s.setslotnumber(rs.getString("slotnumber"));
            north_glass_buffer1s.setdatemodified(rs.getString("datemodified"));
            north_glass_buffer1s.setdatecreated(rs.getString("datecreated"));
            north_glass_buffer1s.setFrameBarcode(rs.getString("FrameBarcode"));
         }
        //  conn.close();
         return north_glass_buffer1s;
    }
 
    public  List<north_glass_buffer1> SelectGlassByGlassIdOrderIdFrameIds(String glassid,String orderid,String frameid) throws SQLException {
        conn = getConn();
        // north_glass_buffer1 glass=new north_glass_buffer1();
        List<north_glass_buffer1> glass=new ArrayList<north_glass_buffer1>();
        String sql = "select * from north_glass_buffer1 where barcode=? or ordernumber=? or FrameBarcode=?";
         ps = conn.prepareStatement(sql);
         ps.setString(1, glassid);
         ps.setString(2, orderid);
         ps.setString(3, frameid);
         rs= ps.executeQuery();
         while (rs.next()) {
            north_glass_buffer1 north_glass_buffer1s=new north_glass_buffer1();
 
            north_glass_buffer1s.setId(rs.getInt("Id"));
            north_glass_buffer1s.setordernumber(rs.getString("ordernumber"));
            north_glass_buffer1s.setlistnumber(rs.getString("listnumber"));
            north_glass_buffer1s.setboxnumber(rs.getString("boxnumber"));
            north_glass_buffer1s.setbarcode(rs.getString("barcode"));
            north_glass_buffer1s.setglasslength(rs.getDouble("glasslength"));
            north_glass_buffer1s.setglassheight(rs.getDouble("glassheight"));
            north_glass_buffer1s.setglasslengthmm(rs.getDouble("glasslength_mm"));
            north_glass_buffer1s.setglassheightmm(rs.getDouble("glassheight_mm"));
            north_glass_buffer1s.setitemtype(rs.getString("itemtype"));
            north_glass_buffer1s.setslotnumber(rs.getString("slotnumber"));
            north_glass_buffer1s.setdatemodified(rs.getString("datemodified"));
            north_glass_buffer1s.setdatecreated(rs.getString("datecreated"));
            north_glass_buffer1s.setFrameBarcode(rs.getString("FrameBarcode"));
 
 
            glass.add(north_glass_buffer1s);
            
         }
        //  conn.close();
         return glass;
    }
    
    /**
     * 1. 加载驱动
     * 2. 获取连接    conn
     * 3. 创建语句 ps
     * 4. 执行语句 rs
     * 5. 处理结果
     * 6. 回收资源
     * 
     * 实现CRUD
     *     更新:
     *         1增加
     *         2删除
     *         3修改
     *  查询:
     *      1. 查一个,一个对象
     *      2. 查一组,做成一个对象列表,查全部
     */
    public static Connection getConn() throws SQLException {
        Connection conn = null;
        conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/canadames?serverTimezone=GMT%2B8&characterEncoding=utf-8", "root", "beibo.123/");
        return conn;
    }
 
    static {
        try {
            Class.forName(DRIVER);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
 
 
}