密文數據源連接發池 ConnectionTools 02

/**
* 關閉Connection 2011-12-30,Xgw123485
*/
public static void closeConn(Connection conn)
{
if (conn != null)
{
try
{
conn.close();
}
catch (Exception e)
{
logger.error("close db Connection failure");
conn = null;
}
}
}

/**
* Close PreparedStatement
*/
public static void closeStmt(PreparedStatement stmt)
{
if(stmt!=null)
{
try
{
stmt.close();
}
catch (Exception e)
{
logger.error("close PreparedStatement failure.");
stmt=null;
}
}
}

/**
* close ResultSet
*/
public static void closeResult(ResultSet rs)
{
if(rs!=null)
{
try
{
rs.close();
}
catch (Exception e)
{
logger.error("Close ResultSet failure.");
rs=null;
}
}
}
public static void main(String[] args) {
Connection connection = getConnection();
try {
Statement statement = connection.createStatement();
statement.executeQuery("select 1 from dual");

statement.close();
connection.close();
} catch (SQLException e) {

e.printStackTrace();
}
}
}
發佈了88 篇原創文章 · 獲贊 0 · 訪問量 4466
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章