1,mysql 链接数据库
方法一:用java 代码直接链接
class.forname("com.mysql.jdbc.Driver");
connection.getmanagerDrvier( jdbc:mysql://localhost:3306/user?user=root&password=123456&characterEncoding=UTF-8);
方法二:properties
static {
InputStream is = null;
is = DBConnectionUtil.class.getClassLoader().getResourceAsStream("jdbc.properties");
Properties p = new Properties();
try {
p.load(is);
jdbcDriver = p.getProperty("jdbcDriver");
jdbcURL = p.getProperty("jdbcURL");
jdbcUser = p.getProperty("jdbcUser");
jdbcPassword = p.getProperty("jdbcPassword");
is.close();
} catch (IOException e) {
e.printStackTrace();
}
方法一:用java 代码直接链接
class.forname("com.mysql.jdbc.Driver");
connection.getmanagerDrvier( jdbc:mysql://localhost:3306/user?user=root&password=123456&characterEncoding=UTF-8);
方法二:properties
static {
InputStream is = null;
is = DBConnectionUtil.class.getClassLoader().getResourceAsStream("jdbc.properties");
Properties p = new Properties();
try {
p.load(is);
jdbcDriver = p.getProperty("jdbcDriver");
jdbcURL = p.getProperty("jdbcURL");
jdbcUser = p.getProperty("jdbcUser");
jdbcPassword = p.getProperty("jdbcPassword");
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}