码迷,mamicode.com
首页 > 数据库 > 详细

java基础-jdbc——三种方式加载驱动建立连接

时间:2015-07-26 18:44:03      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

 1 String url = "jdbc:mysql://localhost:3306/student?Unicode=true&characterEncoding=utf-8";
 2             Properties info = new Properties();
 3             info.put("user", "canon");
 4             info.put("password", "123456");
 5             
 6             /**
 7              * 三种方式加载驱动建立连接
 8              */
 9             //方式1
10             Driver driver = new com.mysql.jdbc.Driver();
11             Connection connection = driver.connect(url, info);
12             
13             /*
14             //方式2
15             Driver driver = DriverManager.getDriver(url);
16             connection = driver.connect(url, info);
17             
18             //方式3
19             Class.forName(url);
20             conn = DriverManager.getConnection(url, info);
21             */

 

java基础-jdbc——三种方式加载驱动建立连接

标签:

原文地址:http://www.cnblogs.com/yang--yang/p/4678152.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!