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
|
*/
|