当前位置:   article > 正文

JDBC连接MySQL的五种方式_jdbc你如何连接mysql properties

jdbc你如何连接mysql properties

JDBC连接数据库的五种方式

1.使用Driver连接:

	public void con1() throws Exception {
   
//		获取驱动
		Driver driver = new Driver();
		String url = "jdbc:mysql://localhost:3306/hsp_db02";
		
		Properties properties = new Properties();
		properties.setProperty("user", "root");
		properties.setProperty("password", "abc123");
//		链接数据库
		Connection connect = driver.connect(url, properties);
//		关闭数据库连接
		connect.close();
	}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

2.使用反射连接:

	public void con2() throws Exception {
   
//		得到驱动文件
		
  • 1
  • 2
  • 3
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号