首页 > 代码库 > jdbc备用记载
jdbc备用记载
package com.yjm.ldapdao; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import org.apache.log4j.Logger; public class DAODB { Connection conn; PreparedStatement pst; ResultSet rs; public static Logger logger = Logger.getLogger(DAODB.class); public DAODB() { } public Connection conn() { try { if (conn == null) { if (LdapConf.log.equals("yes")) { logger.info("创建连接..."); } conn = DriverManager.getConnection(LdapConf.dburl, LdapConf.dbusername, LdapConf.dbpassword); } } catch (SQLException e) { logger.info("创建数据库连接失败..."); logger.info(e); e.printStackTrace(); } return conn; } public void closeConn() { try { if (rs != null) { rs.close(); if (LdapConf.log.equals("yes")) { logger.info("close rs"); } } if (pst != null) { pst.close(); if (LdapConf.log.equals("yes")) { logger.info("close pst"); } } if (conn != null) { conn.close(); logger.info("close conn"); } } catch (SQLException e) { logger.info(e); e.printStackTrace(); } } public PreparedStatement pre(String sql) { try { logger.info("创建 pst..."); pst = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); } catch (SQLException e) { e.printStackTrace(); } return pst; } public ResultSet rs() { try { logger.info("获得结果集..."); rs = pst.executeQuery(); } catch (SQLException e) { logger.info(e); e.printStackTrace(); } return rs; } public void closePreparedStatement() { try { if (pst != null) { pst.close(); logger.info("close pst"); } } catch (SQLException e) { e.printStackTrace(); } } public void closeResultSet() { try { if (rs != null) { rs.close(); logger.info("close rs"); } } catch (SQLException e) { logger.info(e); e.printStackTrace(); } } }
自己按要求写的jdbc 备份复用记载。
jdbc备用记载
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。