Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » 技术文章库  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 [个人原创]通用的JDBC的try…catch…finally模板
jerryjerry123





发贴: 58
积分: 12
于 2005-05-12 10:06 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
在日常的开发中, 我发现JDBC操作的Exception处理方法可总结为下面模板, 希望对大家有用.
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());
}
}


jerryjerry123 edited on 2005-05-12 10:10


话题树型展开
人气 标题 作者 字数 发贴时间
23956 [个人原创]通用的JDBC的try…catch…finally模板 jerryjerry123 1125 2005-05-12 10:06
18192 Re:[个人原创]通用的JDBC的try…catch…finally模板 lqefn 7 2005-06-03 13:53
18642 Re:[个人原创]通用的JDBC的try…catch…finally模板 YuLimin 69 2005-06-04 09:07
18209 Re:[个人原创]通用的JDBC的try…catch…finally模板 serena 128 2005-07-07 10:12
18190 Re:[个人原创]通用的JDBC的try…catch…finally模板 anit 9 2005-06-22 14:01
17902 Re:[个人原创]通用的JDBC的try…catch…finally模板 diystyle 4 2005-07-14 08:54
17875 Re:[个人原创]通用的JDBC的try…catch…finally模板 newbiemen 661 2005-07-20 10:25
18042 Re:[个人原创]通用的JDBC的try…catch…finally模板 wsfx 19 2005-09-08 11:47
19064 Re:[个人原创]通用的JDBC的try…catch…finally模板 wdmsyf 54 2005-11-19 08:27

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923