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