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 PLUS_INF = "`plus_inf`";
|
public static final String PLUS_LOCK_RAM = "`plus_lock_ram`";
|
public static final String PLUS_USER = "`plus_user`";
|
public static final String PLUS_LOCK_HIS = "`plus_lock_his`"; //锁具历史状态库
|
public static final String PLUS_LOCK_ALARM = "`plus_lock_alarm`"; //锁具告警库
|
// 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 DB_LOCK_HIS = "`db_lock_his`"; //锁具历史状态库
|
// public static final String DB_LOCK_ALARM = "`db_lock_alarm`"; //锁具告警库
|
|
/*********************************************************/
|
public static final String Lock_Rt_Table = PLUS_LOCK_RAM + ".tb_lock_rt";
|
public static final String Lock_Ctl_Log_Table = PLUS_LOCK_RAM + ".tb_lock_ctl_log";
|
public static final String Lock_Report_Table = PLUS_LOCK_RAM + ".tb_lock_report"; //锁具开锁次数统计表
|
public static final String Plate_Info_Table = PLUS_LOCK_RAM + ".tb_plate_info"; //平台锁具模式设定表
|
public static final String Lock_IdCard_Table = PLUS_LOCK_RAM + ".tb_lock_idcard"; //锁具已授权ID卡
|
/*********************************************************/
|
/*************** ************ db_area ******************************/
|
public static final String Lock_Inf_Table = PLUS_INF + ".tb_lock_inf";
|
public static final String Key_Inf_Table = PLUS_INF + ".tb_key_inf";
|
public static final String Auth_Idcard_Table = PLUS_INF + ".tb_auth_idcard"; //批量添加授权和取消授权表
|
public static final String Auth_Idcard_His_Table = PLUS_INF + ".tb_auth_idcard_his"; //批量添加授权和取消授权历史表
|
public static final String Lock_BL_Table = PLUS_INF + ".tb_lock_bl"; //蓝牙定时开启计划
|
/*********************************************************/
|
/***************************** db_lock_his ****************************/
|
public static final String Lock_His_Table = PLUS_LOCK_HIS + ".tb_lock_his_"; //锁具开锁次数统计表
|
|
/*********************************************************/
|
/***************************** db_user ****************************/
|
public static final String Process_Survey_Table = PLUS_USER + ".tb_process_survey"; //线程管理表
|
|
/***************************** db_lock_alarm ****************************/
|
|
public static final String Lock_Alarm_Table = PLUS_LOCK_ALARM + ".tb_lock_alarm"; //实时告警
|
public static final String Lock_Alm_Temp_Table = PLUS_LOCK_ALARM + ".tb_lock_alm_temp"; //告警临时表
|
public static final String Lock_Alarm_His_Table = PLUS_LOCK_ALARM + ".tb_lock_alarm_"; //历史告警表
|
|
/*********************************************************/
|
|
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
|
*/
|