博客
关于我
JDBC——(4)获取数据库连接——方式一
阅读量:348 次
发布时间:2019-03-04

本文共 966 字,大约阅读时间需要 3 分钟。

第一种方式获取数据库连接的步骤
1:.提供java.sql.Driver接口实现类的对象
2:提供url,指明具体操作的数据
3:提供Properties的对象,指明用户名和密码
4:调用driver的connect()方法,获取连接

从Java Platform SE 6的文档中找到以下信息

java.sql
接口 Driver
public interface Driver

每个驱动程序类必须实现的接口。Java SQL 框架允许多个数据库驱动程序。每个驱动程序都应该提供一个实现 Driver 接口的类。

方法:
Connection connect(String url, Properties info)
试图创建一个到给定 URL 的数据库连接。

java.sql.Driver 接口是所有 JDBC 驱动程序需要实现的接口。这个接口是提供给数据库厂商使用的,不同数据库厂商提供不同的实现。

// 方式一:	@Test	public void testConnection1() throws SQLException {   		// 获取Driver实现类对象		Driver driver = new com.mysql.jdbc.Driver();		// url:http://localhost:3306/test/keyboard.jpg		// jdbc:mysql:协议		// localhost:ip地址		// 3306:默认mysql的端口号		// test:test数据库		String url = "jdbc:mysql://localhost:3306/jdbc";		// 将用户名和密码封装在Properties中		Properties info = new Properties();		info.setProperty("user", "root");		info.setProperty("password", "zlj18059008512");		Connection conn = driver.connect(url, info);		System.out.println(conn);	}

第一种方式获取数据库连接我们可以知道:显式出现了第三方数据库的API

转载地址:http://nmqq.baihongyu.com/

你可能感兴趣的文章
Nginx 集成Zipkin服务链路追踪
查看>>
nginx 集群配置方式 静态文件处理
查看>>
nginx+php的搭建
查看>>
nginx+tomcat+memcached
查看>>
Nginx+Tomcat实现动静分离
查看>>
nginx+Tomcat性能监控
查看>>
nginx+uwsgi+django
查看>>
nginx+vsftp搭建图片服务器
查看>>
Nginx-http-flv-module流媒体服务器搭建+模拟推流+flv.js在前端html和Vue中播放HTTP-FLV视频流
查看>>
nginx-vts + prometheus 监控nginx
查看>>
nginx: [emerg] getpwnam(“www”) failed 错误处理方法
查看>>
nginx:Error ./configure: error: the HTTP rewrite module requires the PCRE library
查看>>
Nginx、HAProxy、LVS
查看>>
Nginx下配置codeigniter框架方法
查看>>
Nginx中使用expires指令实现配置浏览器缓存
查看>>
Nginx之二:nginx.conf简单配置(参数详解)
查看>>
Nginx代理websocket配置(解决websocket异常断开连接tcp连接不断问题)
查看>>
Nginx代理初探
查看>>
nginx代理地图服务--离线部署地图服务(地图数据篇.4)
查看>>
Nginx代理外网映射
查看>>