首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

一个比较轨范的jdbc连接方法类

2012-07-02 
一个比较规范的jdbc连接方法类主要是留意里面的关闭连接释放资源的写法~public String viewCheck(String i

一个比较规范的jdbc连接方法类

主要是留意里面的关闭连接释放资源的写法~

public String viewCheck(String id) {
?? Session session = factory.openSession();
?? String sumAmount = "";
?? Transaction tx = session.beginTransaction();
?? String sql = "select * from t_merchant_cz where name='"+id+"'";
?? System.out.println(sql);
?? Connection conn = session.connection();??
?? try {
??? Statement stmt = conn.createStatement();
??? ResultSet rs = stmt.executeQuery(sql);
??? if(rs.next()){
???? sumAmount = (String)rs.getString("sum_amount");
??? }
???
?? } catch (Exception e){
??? try {
???? throw e;
??? } catch (Exception se) {
??? }
?? } finally {
??? try {
???? tx.commit();
???? conn.close();
??? } catch (Exception e) {
??? }
??? session.close();
?? }
?? return sumAmount;
}

?

热点排行