通用的JDBC的try…catch…finally模板

Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs=null;

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

// Get connection from DriverManager or from DataSource
conn = DriverManager.getConnection("connection string", "username", "pwd");

stmt = conn.prepareStatement("SELECT count( * ) FROM user_objects order by object_name");
rs = stmt.executeQuery();
if (rs.next())
{
……
……
}
rs.close();

} catch (Exception e)
{
System.out.println("[Exception] - " + e.toString());
} finally {
try {
if (stmt != null)
stmt.close();

if (conn != null)
conn.close();
} catch (Exception fe)
{
System.out.println("[Exception] - " + fe.toString());
}
}

阅读更多
个人分类: java
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

通用的JDBC的try…catch…finally模板

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭