版权声明:版权声明:本文为博主原创文章,未经博主允许不得转载,博客地址:http://blog.csdn.net/xpala https://blog.csdn.net/xpala/article/details/89015598
src下写db.properties 注意没有空格,没有分号
url=jdbc:mysql://localhost/paper
user=root
password=123456
driverClass=com.mysql.jdbc.Driver
DBUtils.java
public class DBUtils {
private static String url=null;
private static String user=null;
private static String password=null;
private static String driverClass=null;
static{
try {
//使用ResourceBundle取数据
ResourceBundle rb=ResourceBundle.getBundle("db");
url=rb.getString("url");
user=rb.getString("user");
password=rb.getString("password");
driverClass=rb.getString("driverClass");
Class.forName(driverClass);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}