try catch finally的应用
来源:互联网 发布:深层网络进入方法 编辑:程序博客网 时间:2024/04/29 16:07
在使用try catch finally时,有时会出现upexcepted exception ... 这里就是你的try块写得有问题了。可能是由于需要
try catch的地方,你没有使用。下面的一个是正常的。
private void QuearyDB(String strSQL)
...{
Connection con = db.getConn ();
Statement stmt = null;
ResultSet rs = null;
try
...{
stmt = con.createStatement();
String querySql = strSQL;
/** *//** 执行查询操作*/
rs = stmt.executeQuery(querySql);
while(rs.next ())
...{
/** *//** 关键词 */
String keyWord = rs.getString (KEY_WORD);
/** *//** 出现次数 */
int count = rs.getInt (APPEAR_COUNT);
double possibleOne = (double)count/ (double)GoodAppearCountSum;
/** *//** 获取另外一个表的相关数据 */
double possibleTwo =GetAnotherPossible(keyWord);
double probility = possibleOne/(possibleOne+possibleTwo);
InsertPossible(keyWord,probility);
}
}
catch (SQLException e)
...{
e.getStackTrace ();
}
finally
...{
if(rs!=null)
...{
try
...{
rs.close ();
}
catch(Exception e)
...{
e.getStackTrace ();
}
}
if(stmt!=null)
...{
try
...{
stmt.close ();
}
catch(Exception e)
...{
e.getStackTrace ();
}
}
}
}
...{
Connection con = db.getConn ();
Statement stmt = null;
ResultSet rs = null;
try
...{
stmt = con.createStatement();
String querySql = strSQL;
/** *//** 执行查询操作*/
rs = stmt.executeQuery(querySql);
while(rs.next ())
...{
/** *//** 关键词 */
String keyWord = rs.getString (KEY_WORD);
/** *//** 出现次数 */
int count = rs.getInt (APPEAR_COUNT);
double possibleOne = (double)count/ (double)GoodAppearCountSum;
/** *//** 获取另外一个表的相关数据 */
double possibleTwo =GetAnotherPossible(keyWord);
double probility = possibleOne/(possibleOne+possibleTwo);
InsertPossible(keyWord,probility);
}
}
catch (SQLException e)
...{
e.getStackTrace ();
}
finally
...{
if(rs!=null)
...{
try
...{
rs.close ();
}
catch(Exception e)
...{
e.getStackTrace ();
}
}
if(stmt!=null)
...{
try
...{
stmt.close ();
}
catch(Exception e)
...{
e.getStackTrace ();
}
}
}
}
- try catch finally的应用
- try...catch...finally的疑问
- try......catch......finally的问题
- JS的try catch finally
- try-catch-finally的使用
- try catch finally的用法
- try-catch-finally的问题
- try catch finally 的执行
- try,catch,finally的用法
- java中try,catch,finally的合理应用
- Java中try-catch-finally语句块的应用
- try-catch-finally的用法之finally
- try-catch-finally的用法之finally
- pb 的try catch finally end try
- try-finally与try-catch-finally的…
- 异常处理的try-catch-finally语句
- JavaScript的例外处理(try...catch...finally)
- 关于try/catch...finally的性能
- [转载]侦测隐藏进程
- Spring学习笔记
- 容易出错的double运算
- 1.3.6 遵照国际标准建设安全的网络
- 一个在开发板上运行的超简单汇编程序--何军
- try catch finally的应用
- [linux手机平台]让应用程序单实例运行
- 最近很郁闷
- JAVA中使用正则表达式
- 《道德情操论》和《国富论》
- 系统分析师考试总结
- SubVersion的相关资料
- JAVA中调用IE浏览器
- 初始化窗体出现位置为屏幕中心