zoukankan      html  css  js  c++  java
  • DBHelper.java(数据库连接类)

    package com.vcredit.ddcash.batch.util;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;

    import org.apache.log4j.Logger;

    public class DBHelper {
    private static final Logger logger=Logger.getLogger(DBHelper.class);

    /**
    * 关闭所有连接
    */
    public static void closeAll(Connection con,Statement statement,ResultSet rs){
    try{
    logger.info("关闭所有连接: Connection:"+con+" | Statement:"+statement+" | ResultSet:"+rs);
    if(null!=con)
    con.close();
    if(null!=statement)
    statement.close();
    if(null!=rs)
    rs.close();
    }catch (SQLException e) {
    logger.info("关闭所有连接失败"+e.getMessage());
    }
    }

    /**
    * 建立连接
    * @return
    */
    public static Connection getConnection(){
    Connection con=null;
    String driver="com.mysql.jdbc.Driver";
    String url=PropertiesUtil.getPropertiesByName("databaseURL");
    String user=PropertiesUtil.getPropertiesByName("databaseUserName");
    String pwd=PropertiesUtil.getPropertiesByName("databasePwd");
    try {
    Class.forName(driver);
    logger.info("Database driver is successfully added!");

    } catch (ClassNotFoundException e) {
    logger.error("Database driver get failed!");
    e.printStackTrace();
    }
    try {
    con=DriverManager.getConnection(url,user,pwd);
    logger.info("Database connection is successful");
    } catch (SQLException e) {
    logger.error("Database connection is failed");
    e.printStackTrace();
    }
    return con;
    }

    }

  • 相关阅读:
    alt属性和title属性
    穷人和富人的区别
    JS经典源码:通用JavaScript脚本函数库
    网页弹出框
    男女交往必知15个真理
    alexa排名
    好男人找不到女朋友的根源
    小笑话集(全是经典!)不信你不笑(转)
    送到家服务网2009年3月26日顺利上线了!
    [转]互联网产品开发中的“快”字诀
  • 原文地址:https://www.cnblogs.com/muliu/p/6145193.html
Copyright © 2011-2022 走看看