java链接数据库

来源:互联网 发布:网络招聘沟通技巧 编辑:程序博客网 时间:2024/05/22 07:56
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();
}

}


原创粉丝点击