?? dbconnectionmanager.java
字號:
package cn.com.iaspec.workflow.db;
import java.sql.*;
import org.apache.log4j.*;
/**
*
* <p>Title:數據庫連接池管理</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: IASPEC Technologies</p>
* @author xiesonglin
* @version 1.0
*/
public class DBConnectionManager{
protected boolean useJNDIConnection=true;
private DBConnectionPool pool;
public static long connectCount=0;
public static long freeCount=0;
protected String dataBaseType="ORACLE";
private static Logger logger=Logger.getLogger(DBConnectionManager.class);
public void Close(PreparedStatement preStm,boolean closeConnection){
logger.debug("begin Close(PreparedStatement preStm)...");
try{
if(preStm!=null){
if(closeConnection){
Connection connection=null;
connection=preStm.getConnection();
close(connection);
}
preStm.close();
preStm=null;
}
}
catch(Exception ex){
ex.printStackTrace();
}
}
public String getDataBaseType(){
return dataBaseType==null?"":dataBaseType.toUpperCase();
}
public void Close(CallableStatement callStm,boolean closeConnection){
logger.debug("begin Close(CallableStatement callStm)...");
try{
if(callStm!=null){
if(closeConnection){
Connection connection=null;
connection=callStm.getConnection();
close(connection);
}
callStm.close();
callStm=null;
}
}
catch(Exception ex){
ex.printStackTrace();
}
}
public void close(ResultSet resultSet){
logger.debug("begin Close(ResultSet resultSet)...");
try{
if(resultSet!=null){
resultSet.close();
resultSet=null;
}
}
catch(Exception ex){
ex.printStackTrace();
}
}
public void close(Statement statement,boolean closeConnection){
logger.debug("begin Close(Statement statement)...");
try{
if(statement!=null){
if(closeConnection){
Connection connection=null;
connection=statement.getConnection();
close(connection);
}
statement.close();
statement=null;
}
}
catch(Exception ex){
ex.printStackTrace();
}
}
public synchronized void addConnectCount(){
this.connectCount++;
logger.debug("connectCount is:"+connectCount);
}
public synchronized void close(Connection connection){
try{
logger.debug("begin Close(Connection connection)");
if(connection!=null){
if(!useJNDIConnection){
freeConnection(connection);
this.freeCount++;
}
else{
if(!connection.isClosed()){
connection.close();
this.freeCount++;
}
connection=null;
}
}
logger.debug("freeCount is:"+freeCount);
}
catch(Exception ex){
ex.printStackTrace();
}
}
/**
* rollback DB transaction
* @param connection
* @throws SQLException
*/
public void rollBackConnection(Connection connection){
if(connection!=null){
try{
if(!connection.getAutoCommit()){
connection.rollback();
}
}
catch(Exception e){
e.printStackTrace();
}
}
}
/**
* Free a connection
* @param con connection
* @throws SQLException this method
*/
public void freeConnection(Connection con)
throws SQLException{
if(pool!=null){
pool.freeConnection(con);
}
}
public void setDataBaseType(String dataBaseType){
this.dataBaseType=dataBaseType;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -