java sql 万能库_万能数据库连接类-Oracle、DB2 、Access 、Sql Server

package cc.apps.report;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import com.order.cc.sys.dao.FoJdbcDaoSupport;

public class connectData extends FoJdbcDaoSupport{

/* 连接Oracle */

String strIVRUrl = "jdbc:oracle:thin:@127.0.0.1:1521:ccdb";

String strIVRUser = "";

String strIVRPASS = "";

/* 连接DB2 */

String strCTIUrl = "jdbc:db2://**:6789/CTIDB";

String strCTIUser = "";

String strCTIPASS = "";

/* 连接Access */

String strAccUrl = "jdbc:odbc:220acc97";

String strAccUser = "";

String strAccPASS = "";

/* 连接Sql Server */

String strSqlUrl = "jdbc:sqlserver://**:1433;DatabaseName=**";

String strSqlUser = "**";

String strSqlPASS = "**";

Connection connI = null;

Connection connC = null;

Connection connA = null;

public Connection connectIVR() throws SQLException {

try {

Class.forName("oracle.jdbc.driver.OracleDriver");

connI = DriverManager.getConnection(strIVRUrl, strIVRUser, strIVRPASS);

}

catch (Exception e) {

e.printStackTrace();

logger.error(e.getMessage());

}

return connI;

}

public Connection connectCTI() throws SQLException {

try {

Class.forName("COM.ibm.db2.jdbc.net.DB2Driver");

connC = DriverManager.getConnection(strCTIUrl, strCTIUser, strCTIPASS);

}

catch (Exception e) {

e.printStackTrace();

logger.error(e.getMessage());

}

return connC;

}

public Connection connectACC() throws SQLException {

try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

connA = DriverManager.getConnection(strAccUrl, strAccUser, strAccPASS);

}

catch (Exception e) {

e.printStackTrace();

logger.error(e.getMessage());

}

return connA;

}

public Connection connectSQL() throws SQLException {

try {

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

connA = DriverManager.getConnection(strSqlUrl, strSqlUser, strSqlPASS);

}

catch (Exception e) {

e.printStackTrace();

logger.error(e.getMessage());

}

return connA;

}

}

-------------------------调用方法-------------------------------------

public class ReportDAO extends connectData implements IReportDAO {

public ResultEntity queryComCheackCountRes(String year, String month, String monthEnd, String groupName) {

ResultEntity res = new ResultEntity();

List dateList = new ArrayList();

Connection conn = null;

ResultSet rs = null;

Statement stmt = null;

try {

conn = connectSQL();

conn = this.getConnection();

stmt = conn.createStatement();

String sql = getSql(year, month, monthEnd, groupName);

rs = stmt.executeQuery(sql);

Map avgMap = new HashMap();

while (rs.next()) {

getRsDateList(dateList, rs, avgMap);

}

res.setList(dateList);

res.setAvgMap(avgMap);

} catch (SQLException sqle) {

sqle.printStackTrace();

} catch (Exception ex) {

ex.printStackTrace();

} finally {

try {

if (rs != null)

rs.close();

if (stmt != null)

stmt.close();

if (conn != null)

conn.close();

} catch (SQLException sqe) {

sqe.printStackTrace();

}

}

return res;

}

标签:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值