package com.sql;
|
|
import com.base.Com;
|
import com.config.AppConfig;
|
import java.sql.Connection;
|
import java.sql.DriverManager;
|
import java.sql.ResultSet;
|
import java.sql.SQLException;
|
import java.sql.Statement;
|
import java.util.GregorianCalendar;
|
import java.util.Properties;
|
|
public class Sql_Sybase {
|
public static final int SQL_TYPE_SYBASE_DEMO = 0;
|
public static final int SQL_TYPE_SYBASE = 1;
|
public static final int SQL_TYPE_MSSQLSERVER = 2;
|
private int m_SQL_TYPE = 0;
|
|
private String mSQLServerIp = "127.0.0.1";
|
private String mSQLServerUsrName = "sxfg001";
|
private String mSQLServerPWD = "sxfg001";
|
private int mSQLServerPort = 5000;
|
|
private ResultSet sql_res = null;
|
private Connection sql_conn = null;
|
|
public Sql_Sybase(AppConfig cfg) {
|
this.m_SQL_TYPE = cfg.getSourceSQLServerType();
|
this.mSQLServerIp = cfg.getSourceSQLServerIp();
|
this.mSQLServerUsrName = cfg.getSourceSQLServerUsrName();
|
this.mSQLServerPWD = cfg.getSourceSQLServerPWD();
|
this.mSQLServerPort = cfg.getSourceSQLServerPort();
|
|
this.sql_conn = getConnection();
|
}
|
|
public int get_SQL_TYPE() {
|
return this.m_SQL_TYPE;
|
}
|
|
public String getQueryVolString(String st_id, GregorianCalendar gc_start, GregorianCalendar gc_end,
|
String time_order) {
|
String str = "";
|
if (1 == this.m_SQL_TYPE) {
|
str = "SELECT StationId,EquipmentId,SignalId,FloatValue FROM HistoryBattery" + (gc_start.get(2) + 1)
|
+ " WHERE " + " StationId=" + st_id + " AND RecordTime>'"
|
+ Com.getDateTimeFormat(gc_start.getTime(), "yyyy-MM-dd HH:mm:ss") + "'" + " AND RecordTime<='"
|
+ Com.getDateTimeFormat(gc_end.getTime(), "yyyy-MM-dd HH:mm:ss") + "'" + " ORDER BY RecordTime "
|
+ time_order;
|
} else if (this.m_SQL_TYPE == 0) {
|
str = "SELECT StationId,EquipmentId,SignalId,FloatValue FROM HistoryBattery" + (gc_start.get(2) + 1)
|
+ " WHERE " + " StationId='" + st_id + "'" + " AND RecordTime>'"
|
+ Com.getDateTimeFormat(gc_start.getTime(), "yyyy-MM-dd HH:mm:ss") + "'" + " AND RecordTime<='"
|
+ Com.getDateTimeFormat(gc_end.getTime(), "yyyy-MM-dd HH:mm:ss") + "'" + " ORDER BY RecordTime "
|
+ time_order;
|
} else if (2 == this.m_SQL_TYPE) {
|
str = "SELECT StationId,EquipmentId,SignalId,FloatValue FROM TBL_HistorySignal" + (gc_start.get(2) + 1)
|
+ " WHERE " + " StationId=" + st_id + " AND SampleTime>'"
|
+ Com.getDateTimeFormat(gc_start.getTime(), "yyyy-MM-dd HH:mm:ss") + "'" + " AND SampleTime<='"
|
+ Com.getDateTimeFormat(gc_end.getTime(), "yyyy-MM-dd HH:mm:ss") + "'" + " ORDER BY SampleTime "
|
+ time_order;
|
}
|
return str;
|
}
|
|
public String getQueryCurrentString(String st_id, GregorianCalendar gc_start, GregorianCalendar gc_end,
|
String time_order) {
|
String str = "";
|
if (1 == this.m_SQL_TYPE) {
|
str = "SELECT StationId,EquipmentId,SignalId,FloatValue FROM HistorySignal" + (gc_start.get(2) + 1)
|
+ " WHERE " + " StationId=" + st_id + " AND RecordTime >'"
|
+ Com.getDateTimeFormat(gc_start.getTime(), "yyyy-MM-dd HH:mm:ss") + "'" + " AND RecordTime <='"
|
+ Com.getDateTimeFormat(gc_end.getTime(), "yyyy-MM-dd HH:mm:ss") + "'" + " ORDER BY RecordTime "
|
+ time_order;
|
}
|
|
return str;
|
}
|
|
public Connection getConnection() {
|
Connection con = null;
|
if ((this.m_SQL_TYPE == 0) || (1 == this.m_SQL_TYPE)) {
|
try {
|
Class.forName("com.sybase.jdbc3.jdbc.SybDriver").newInstance();
|
String url = "jdbc:sybase:Tds:" + this.mSQLServerIp + ":" + this.mSQLServerPort + "/SiteWeb";
|
Properties sysProps = System.getProperties();
|
sysProps.put("user", this.mSQLServerUsrName);
|
sysProps.put("password", this.mSQLServerPWD);
|
|
con = DriverManager.getConnection(url, sysProps);
|
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException
|
| SQLException localInstantiationException) {
|
}
|
|
} else if (2 == this.m_SQL_TYPE) {
|
try {
|
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
|
String url = "jdbc:sqlserver://" + this.mSQLServerIp + ";DatabaseName=SiteWeb";
|
|
con = DriverManager.getConnection(url, this.mSQLServerUsrName, this.mSQLServerPWD);
|
} catch (ClassNotFoundException | SQLException localClassNotFoundException) {
|
}
|
}
|
return con;
|
}
|
|
public ResultSet getSqlres() {
|
return this.sql_res;
|
}
|
|
public void close_conn() throws SQLException {
|
if (this.sql_conn != null) {
|
this.sql_conn.close();
|
this.sql_conn = null;
|
}
|
}
|
|
public boolean get_conn_state() {
|
if (this.sql_conn == null)
|
return false;
|
return true;
|
}
|
|
public ResultSet sqlSybaseQuery(String sql_str) throws SQLException {
|
Statement sql = this.sql_conn.createStatement();
|
sql.setQueryTimeout(30);
|
ResultSet rs = sql.executeQuery(sql_str);
|
return rs;
|
}
|
|
public void sqlSybaseExecute(String str) throws SQLException {
|
Statement sql = this.sql_conn.createStatement();
|
sql.setQueryTimeout(30);
|
sql.execute(str);
|
}
|
}
|
|
/*
|
* Location:
|
* C:\Users\LiJun\Desktop\公司各种设备资料\9600显示模块相关文件\后台程序\2018-09-07\BattFBS9600XSP.
|
* jar Qualified Name: com.sql.Sql_Sybase JD-Core Version: 0.6.2
|
*/
|