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;
}

}

最新文章

  1. iOS 适配iOS9
  2. 算法与设计模式系列1之Python实现常见算法
  3. 利用Delphi的File Of Type创建并管理属于你自己的数据库
  4. delphi函数调用约定
  5. A real ROCA using Bootstrap, jQuery, Thymeleaf, Spring HATEOAS and Spring MVC
  6. ios的手势操作之UIGestureRecognizer浅析
  7. 面试题 43 n 个骰子的点数
  8. mysql的查询缓存
  9. Oracle之 any 、some、all解析
  10. React(17)异步组件
  11. 【安富莱专题教程第1期】基于STM32的硬件RGB888接口实现emWin的快速刷新方案,32位色或24
  12. Windows server 2008 R2实现多用户远程连接 (转)
  13. linux执行可执行文件时报xxx:not found
  14. 【BZOJ3240】【UOJ#124】【NOI2013】矩阵游戏
  15. Nginx开启Gzip详解
  16. linux下用命令修改文件内容
  17. python学习 day21 (3月28日)----(抽象类 多态 nametuple dump)
  18. jQuery显示SQL存储过程自定义异常信息
  19. mac 关闭显示器 & 快捷键
  20. ASP.NET MVC:WebPageRenderingBase.cs

热门文章

  1. JavaScript设计模式——工厂模式
  2. Oracle常用命令
  3. 《DSP using MATLAB》示例Example4.8
  4. DSP using MATLAB 示例 Example3.15
  5. express-17 持久化
  6. Ubuntu mysql
  7. Swift3.0语言教程获取字符串长度
  8. wpf中dropdownButton控件下拉居中。。。
  9. 当 NSDictionary 遇见 nil
  10. java基础-变量