标签:rop resource stream oid unicode password pass vat als
db.properties
driverClass=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/test_db?useUnicode=true&characterEncoding=UTF-8&jdbcCompliantTruncation=false user=root password=
commonsDbutils工具类
public class CommonsDbutils {
private static Connection conn;
private static String driverClass;
private static String url;
private static String user;
private static String password;
static {
try {
readDBConfig();
Class.forName(driverClass);
conn = DriverManager.getConnection(url, user, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void readDBConfig(){
try {
InputStream in = CommonsDbutils.class.getClassLoader().getResourceAsStream("db.properties");
Properties pro = new Properties();
pro.load(in);
driverClass = pro.getProperty("driverClass");
url = pro.getProperty("url");
user = pro.getProperty("user");
password = pro.getProperty("password");
} catch (IOException e) {
e.printStackTrace();
}
}
public static Connection getConnection(){
return conn;
}
}
标签:rop resource stream oid unicode password pass vat als
原文地址:https://www.cnblogs.com/achengmu/p/10911083.html