DELL
2024-12-16 13b303d0d82e77f7cc7bf1daa7a56d1299ac04d2
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
142
143
144
145
146
147
148
149
150
package com.sql;
 
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
 
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
 
public class Sql_Mysql {
    public static final String DB_AREA         = "`db_area`";
    public static final String DB_LOCK_RAM     = "`db_lock_ram`";
    public static final String DB_USER         = "`db_user`";
 
    /*********************************************************/
    public static final String Lock_Rt_Table         = DB_LOCK_RAM + ".tb_lock_rt";
    public static final String Lock_Ctl_Log_Table     = DB_LOCK_RAM + ".tb_lock_ctl_log";
    /*********************************************************/
    /***************  ******************************************/
    public static final String Lock_Inf_Table         = DB_AREA + ".tb_lock_inf";
    /*********************************************************/
    
    public Logger logger;
    public Connection mysql_con;
 
    public Sql_Mysql(Connection conn) {
        this.mysql_con = conn;
        logger = LogManager.getLogger(this.getClass());
    }
 
    public void close_con() {
        try {
            this.mysql_con.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
 
 
    public boolean sqlMysqlCheckIfTableExist(String tb) throws SQLException {
        String sql_str = "SHOW TABLES LIKE '" + tb + "'";
        ResultSet res = sqlMysqlQuery(sql_str);
        boolean exist = false;
        if (res.next()) {
            exist = true;
        }
 
        return exist;
    }
 
    public void sqlMysqlExecute(String sql_str) throws SQLException {
        Statement sql = this.mysql_con.createStatement();
        sql.setQueryTimeout(30);
        sql.execute(sql_str);
    }
    public void sqlMysqlTotalExecute(String sql_str) throws SQLException {
        Statement sql = this.mysql_con.createStatement();
        sql.setQueryTimeout(60*10);
        sql.execute(sql_str);
    }
 
    public boolean makeManualCommit(ArrayList<String> al_sql_strs) {
        boolean exe_res = true;
        try {
            this.mysql_con.setAutoCommit(false);
 
            for (int n = 0; n < al_sql_strs.size(); n++) {
                sqlMysqlExecute((String) al_sql_strs.get(n));
            }
 
            if (exe_res)
                this.mysql_con.commit();
        } catch (SQLException e) {
            e.printStackTrace();
            exe_res = false;
            try {
                if (!exe_res) {
                    this.mysql_con.rollback();
                }
                this.mysql_con.setAutoCommit(true);
            } catch (SQLException e1) {
                e1.printStackTrace();
            }
        } finally {
            try {
                if (!exe_res) {
                    this.mysql_con.rollback();
                }
                this.mysql_con.setAutoCommit(true);
            } catch (SQLException e1) {
                e1.printStackTrace();
            }
        }
 
        return exe_res;
    }
 
    public ResultSet sqlMysqlQuery(String sql_str) {
        ResultSet res = null;
        try {
            Statement sql = this.mysql_con.createStatement();
            sql.setQueryTimeout(30);
            String query = sql_str;
            res = sql.executeQuery(query);
        } catch (SQLException ex) {
            System.err.println("SQLException:" + ex.getMessage());
        }
 
        return res;
    }
    
    public ResultSet sqlMysqlTotalQuery(String sql_str) {
        ResultSet res = null;
        try {
            Statement sql = this.mysql_con.createStatement();
            sql.setQueryTimeout(60*5);
            String query = sql_str;
            res = sql.executeQuery(query);
        } catch (SQLException ex) {
            System.err.println("SQLException:" + ex.getMessage());
        }
 
        return res;
    }
 
    public void sqlMysqlUpdate(String sql_str) {
        try {
            Statement sql = this.mysql_con.createStatement();
            sql.setQueryTimeout(30);
            String query = sql_str;
            sql.execute(query);
        } catch (SQLException ex) {
            System.out.println("SQLException:" + ex.getMessage());
        }
    }
 
 
 
    
 
    
}
 
/*
 * Location:
 * C:\Users\LiJun\Desktop\公司各种设备资料\9600显示模块相关文件\后台程序\2018-09-07\BattFBS9600XSP.
 * jar Qualified Name: com.sql.Sql_Mysql JD-Core Version: 0.6.2
 */