JdbcUnit的使用
来源:互联网 发布:mac充电先绿灯后变红 编辑:程序博客网 时间:2024/05/21 21:33
package com.altest.units;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
public class JdbcUnit {
private static Properties properties = null;
// 只在JdbcUnits被加载时,执行一次
static {
// 给properties 进行初始化,加载 dbconfig.properties文件到 propertie 中去
try {
InputStream inputStream = JdbcUnit.class.getClassLoader().getResourceAsStream("dbconfig.properties");
properties = new Properties();
properties.load(inputStream);
} catch (IOException e) {
e.printStackTrace();
}
//加载驱动类
try {
Class.forName(properties.getProperty("driveClassName"));
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static Connection getConnection() throws SQLException{
return DriverManager.getConnection(properties.getProperty("url"),properties.getProperty("username"),properties.getProperty("password"));
}
public static void CloseJdbc(ResultSet resultSet, PreparedStatement preparedStatement,
Connection connection) {
try {
if (resultSet != null) {
resultSet.close();
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (preparedStatement != null)
preparedStatement.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (connection != null)
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
public class JdbcUnit {
private static Properties properties = null;
// 只在JdbcUnits被加载时,执行一次
static {
// 给properties 进行初始化,加载 dbconfig.properties文件到 propertie 中去
try {
InputStream inputStream = JdbcUnit.class.getClassLoader().getResourceAsStream("dbconfig.properties");
properties = new Properties();
properties.load(inputStream);
} catch (IOException e) {
e.printStackTrace();
}
//加载驱动类
try {
Class.forName(properties.getProperty("driveClassName"));
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static Connection getConnection() throws SQLException{
return DriverManager.getConnection(properties.getProperty("url"),properties.getProperty("username"),properties.getProperty("password"));
}
public static void CloseJdbc(ResultSet resultSet, PreparedStatement preparedStatement,
Connection connection) {
try {
if (resultSet != null) {
resultSet.close();
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (preparedStatement != null)
preparedStatement.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (connection != null)
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
0 0
- JdbcUnit的使用
- 自制ORM框架—JdbcUnit总结
- GUID使用的使用
- ${}的使用
- 的使用
- @[],@()的使用
- ->的使用
- +、-、*、/、%的使用
- &&的使用
- %:的使用
- Makefile中使用$$的使用
- Makefile中使用$$的使用
- Red5的使用--使用日志
- prefernce的使用具体使用
- 【工具使用】git 的使用
- 关于使用AsyncTaskLoader的使用
- 使用CABasicAnimation的基本使用
- 使用RocketMQ的客户端使用
- 电信pme流程管理引擎系统视频
- DNS,edns,httpdns杂谈
- 利用反射实现对象与map的互转
- php学习线路
- android getResources.getColor(R.color.colorId)方法遭弃用
- JdbcUnit的使用
- 微信小程序快捷键(来源百度经验)
- Android 自定义实现类似QQ消息贝塞尔拖拽效果BezierView
- 给按钮加前景色和字体大小(Java_Swing)
- 1009. Product of Polynomials (25)
- POJ 3259 Wormholes 最短路径
- Android 顶部悬浮栏 + ViewPager + RecyclerView
- 数据结构-散列
- oracle 远程连接提示 ora-12541错误