Connection conn = null;
ResultSet rs = null;
preparedStatement pss = null;
try
{
conn = dataSource.getConnection(USERID,pASSWORD);
pss = conn.prepareStatement("SELECT SAVESERIALZEDDATA FROM SESSION.pINGSESSION3DATA WHERE SESSIONKEY = ?");
pss.setString(1,sessionKey);
rs = pss.executeQuery();
pss.close();
conn.close();
}
catch (Throwable t)
{
// Insert Appropriate Error Handling Here
}
finally
{
// The finally clause is always executed - even in error
// conditions preparedStatements and Connections will always be closed
try
{
if (pss != null)
pss.close();
}
catch(Exception e) {}
try
{
if (conn != null)
conn.close();
}
catch (Exception e){}
}
}
connection 关闭方法
最新推荐文章于 2025-03-25 13:48:56 发布
本文展示了一段使用 Java 进行数据库连接并执行 SQL 查询的代码示例。通过数据源获取连接,并利用 PreparedStatement 执行带有参数的 SQL 语句,该语句用于从指定表中检索与 sessionKey 相匹配的数据。
2823

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



