package com.sql;
|
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;
|
|
import com.base.Com;
|
import com.config.AppConfig;
|
|
public class Sql_Sybase
|
{
|
public final static int SQL_TYPE_SYBASE_DEMO = 0;
|
public final static int SQL_TYPE_SYBASE = 1;
|
public final static int SQL_TYPE_MSSQLSERVER = 2;
|
private int m_SQL_TYPE = SQL_TYPE_SYBASE_DEMO;
|
//´´½¨Êý¾Ý¿âÁ¬½Ó³Ø
|
//private ComboPooledDataSource sybase_ds = new ComboPooledDataSource();
|
|
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)
|
{
|
m_SQL_TYPE = cfg.getSourceSQLServerType();
|
mSQLServerIp = cfg.getSourceSQLServerIp();
|
mSQLServerUsrName = cfg.getSourceSQLServerUsrName();
|
mSQLServerPWD = cfg.getSourceSQLServerPWD();
|
mSQLServerPort = cfg.getSourceSQLServerPort();
|
|
sql_conn = getConnection();
|
}
|
|
public int get_SQL_TYPE()
|
{
|
return m_SQL_TYPE;
|
}
|
|
|
|
|
|
|
public Connection getConnection(){
|
Connection con = null;
|
if((SQL_TYPE_SYBASE_DEMO == m_SQL_TYPE) || (SQL_TYPE_SYBASE == m_SQL_TYPE))
|
{
|
try {
|
Class.forName("com.sybase.jdbc3.jdbc.SybDriver").newInstance();
|
String url = "jdbc:sybase:Tds:" + mSQLServerIp + ":" + mSQLServerPort + "/SiteWeb";
|
Properties sysProps = System.getProperties();
|
sysProps.put("user", mSQLServerUsrName);
|
sysProps.put("password", mSQLServerPWD);
|
|
con = DriverManager.getConnection(url, sysProps);
|
} catch (InstantiationException | IllegalAccessException
|
| ClassNotFoundException | SQLException e) {
|
//e.printStackTrace();
|
//System.err.println(e.getMessage());
|
}
|
}
|
else if(SQL_TYPE_MSSQLSERVER == m_SQL_TYPE)
|
{
|
try {
|
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
|
String url = "jdbc:sqlserver://" + mSQLServerIp + ";DatabaseName=SiteWeb";
|
/*
|
String userName = "fuguang";
|
String userPwd = "jian(12)";
|
*/
|
con = DriverManager.getConnection(url, mSQLServerUsrName, mSQLServerPWD);
|
} catch (ClassNotFoundException | SQLException e) {
|
//e.printStackTrace();
|
}
|
}
|
|
return con;
|
}
|
|
|
public ResultSet getSqlres()
|
{
|
return sql_res;
|
}
|
public void close_conn() throws SQLException
|
{
|
if(null != sql_conn)
|
{
|
sql_conn.close();
|
sql_conn = null;
|
}
|
}
|
public boolean get_conn_state()
|
{
|
if(null == sql_conn)
|
return false;
|
else return true;
|
}
|
|
/**
|
* ¸ù¾Ý²éѯÓï¾ä»ñÈ¡ ResultSet ¼¯ºÏ
|
* @param sql_str ²éѯÓï¾ä
|
* @return ResultSet¼¯ºÏ
|
* @throws SQLException
|
*/
|
public ResultSet sqlSybaseQuery(String sql_str) throws SQLException
|
{
|
Statement sql = sql_conn.createStatement();
|
sql.setQueryTimeout(30);
|
ResultSet rs = sql.executeQuery(sql_str);
|
return rs;
|
}
|
|
public void sqlSybaseExecute(String str) throws SQLException
|
{
|
Statement sql = sql_conn.createStatement();
|
sql.setQueryTimeout(30);
|
sql.execute(str);
|
}
|
}
|