博客
关于我
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总结及使用Docker创建nginx教程
查看>>
nginx报错:the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:128
查看>>
nginx报错:the “ssl“ parameter requires ngx_http_ssl_module in usrlocalnginxconfnginx.conf128
查看>>
nginx日志分割并定期删除
查看>>
Nginx日志分析系统---ElasticStack(ELK)工作笔记001
查看>>
Nginx映射本地json文件,配置解决浏览器跨域问题,提供前端get请求模拟数据
查看>>
Nginx映射本地静态资源时,浏览器提示跨域问题解决
查看>>
nginx最最最详细教程来了
查看>>
Nginx服务器---正向代理
查看>>
Nginx服务器上安装SSL证书
查看>>
Nginx服务器基本配置
查看>>
Nginx服务器的安装
查看>>
Nginx标准配置文件(包括反向代理、大文件上传、Https证书配置、文件预览等)
查看>>
Nginx模块 ngx_http_limit_conn_module 限制连接数
查看>>
Nginx模块 ngx_http_limit_req_module 限制请求速率
查看>>
nginx添加允许跨域header头
查看>>
nginx添加模块与https支持
查看>>
nginx状态监控
查看>>
Nginx用户认证
查看>>
Nginx的location匹配规则的关键问题详解
查看>>