/**
* 关闭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();
}
}
}
* 关闭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();
}
}
}
本文详细介绍了数据库连接管理中的关键方法,包括关闭数据库连接、预编译语句和结果集的操作,确保资源的有效利用。

被折叠的 条评论
为什么被折叠?



