properties配置文件的使用
来源:互联网 发布:java工程师培训价格 编辑:程序博客网 时间:2024/05/23 02:01
jdbc.properties:
driverclass=com.mysql.jdbc.Driverurl=jdbc:mysql:///mydb1username=rootpassword=root
JDBCTools.java:
主要看静态代码块的应用
import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ResourceBundle;public class JDBCTools { private static final String DRIVERCLASS; private static final String URL; private static final String USER; private static final String PASSWORD; static{ DRIVERCLASS = ResourceBundle.getBundle("jdbc").getString("driverclass"); URL = ResourceBundle.getBundle("jdbc").getString("url"); USER = ResourceBundle.getBundle("jdbc").getString("username"); PASSWORD = ResourceBundle.getBundle("jdbc").getString("password"); } public static Connection getConnection() throws Exception{ //1.加载驱动 Class.forName(DRIVERCLASS); //2.建立连接 Connection conn = DriverManager.getConnection(URL, USER, PASSWORD); return conn; } public static void closeResultSet(ResultSet rs) throws SQLException{ if(rs != null){ rs.close(); } } public static void closePreparedStatement(PreparedStatement pst) throws SQLException{ if(pst != null){ pst.close(); } } public static void closeConnetion(Connection con) throws SQLException{ if(con != null){ con.close(); } } private JDBCTools(){}}
阅读全文
0 0
- 配置文件properties的使用
- 配置文件的使用 Properties
- 配置文件(.properties)的使用
- properties配置文件的使用
- properties配置文件的简单使用
- java中的配置文件(Properties)的使用
- properties配置文件的读取和使用
- JAVA——配置文件Properties的使用
- Android自定义配置文件(.properties文件)的使用
- Spring中使用外部的properties配置文件
- java中配置文件.properties的使用
- Spring 使用Properties配置文件
- log4j.properties配置文件使用
- JAVA 使用properties配置文件
- 使用properties配置文件
- 使用配置文件properties
- 使用properties读取配置文件
- 如何使用Properties配置文件
- 在dw的itemchanged事件里面,修改当前参数data
- MySQL索引
- 关于素数筛法的一点讨论
- 远程桌面无法复制文件解决方法
- Longest Substring Without Repeating Characters
- properties配置文件的使用
- 哈希表
- banner listview (无限轮播+ listview)
- Linux系统Oracle定时删除归档日志
- Source Insight基本使用和快捷键
- 守护进程以及fork两次的问题
- 二项堆与斐波那契堆
- ubuntu17.04插上网线没反应(设备未托管)
- perparestatement在mysql中的普通使用