Properties文件的读取。
2016-05-12 12:04
295 查看
db.properties jdbc.driver=oracle.jdbc.OracleDriver jdbc.url=jdbc:oracle:thin:@localhost:ORCL jdbc.user=root jdbc.password= import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.Properties; public class DBUtility { private static Properties properties =new Properties() ; private static String driver = null; private static String url = null; private static String user = null; private static String pwd = null; static { try { // 加载配置文件 properties.load(DBUtility.class.getClassLoader().getResourceAsStream( "day01/v3/db.properties")); driver = properties.getProperty("jdbc.driver"); url = properties.getProperty("jdbc.url"); user = properties.getProperty("jdbc.user"); pwd = properties.getProperty("jdbc.password"); Class.forName(driver); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } } public static Connection openConnection() throws SQLException { return DriverManager.getConnection(url, user, pwd); } public static void closeConnection(Connection con) { if (con != null) { try { con.close(); } catch (SQLException e) { System.out.println("关闭连接时发生异常"); } } } }
相关文章推荐
- ecshop后台 计划任务
- CentOS 7.x 下配置 DHCP 服务器 基础篇
- Linux下搭建Android开发环境及Android真机调试
- apache commons io 依赖度
- 《Linux驱动》驱动注册
- LearnOpenCV学习——平均脸
- Centos 7 yum 安装 mysql5.7
- 利用linux的mtrace命令定位内存泄露(Memory Leak)
- ZOJ3944 People Counting ZOJ3939 The Lucky Week (模拟)
- GIT简介以及在Centos上的安装
- Linux(一)
- linux系统调用原理
- Centos配置国内yum源
- Linux中常用操作命令
- Linux常用命令
- Centos7 创建个文件 thread 怪现象
- linux shell 提取变量 变量传参
- pc机安装centos6.5,提示sda必须有一个GPT磁盘标签处理
- linux中Framebuffer的原理及实现机制
- linux dup/dup2