getConnection 区别
1. 这是一个接口
package javax.sql;
DataSource.class
/**
* <p>Attempts to establish a connection with the data source that
* this <code>DataSource</code> object represents.
*
* @return a connection to the data source
* @exception SQLException if a database access error occurs
*/
Connection getConnection() throws SQLException;
2.这是一个dbcp实现类,返回由连接池管理的连接。
package org.apache.commons.dbcp2;
BasicDataSource.class
/**
* Create (if necessary) and return a connection to the database.
*
* @throws SQLException if a database access error occurs
* @return a database connection
*/
@Override
public Connection getConnection() throws SQLException {
if (Utils.IS_SECURITY_ENABLED) {
PrivilegedExceptionAction<Connection> action = new PaGetConnection();
try {
return AccessController.doPrivileged(action);
} catch (PrivilegedActionException e) {
Throwable cause = e.getCause();
if (cause instanceof SQLException) {
throw (SQLException) cause;
}
throw new SQLException(e);
}
}
return createDataSource().getConnection();
}
3. 创建连接并返回
package java.sql;
DriverManager.class
/**
* Attempts to establish a connection to the given database URL.
* The <code>DriverManager</code> attempts to select an appropriate driver from
* the set of registered JDBC drivers.
*
* @param url a database url of the form
* <code>jdbc:<em>subprotocol</em>:<em>subname</em></code>
* @param user the database user on whose behalf the connection is being
* made
* @param password the user's password
* @return a connection to the URL
* @exception SQLException if a database access error occurs
*/
public static Connection getConnection(String url,
String user, String password) throws SQLException {
java.util.Properties info = new java.util.Properties(); // Gets the classloader of the code that called this method, may
// be null.
ClassLoader callerCL = DriverManager.getCallerClassLoader(); if (user != null) {
info.put("user", user);
}
if (password != null) {
info.put("password", password);
} return (getConnection(url, info, callerCL));
}
getConnection 区别的更多相关文章
- MySql学习笔记--详细整理--下
目录 索引 测试索引 索引原则 权限管理和备份 备份 规范数据库设计 三大范式 JDBC JDBC程序 Statement对象 工具类实现 sql注入 PreparedStatement对象 事务 数 ...
- (十)JDBC(重点)
10.1 数据库驱动 驱动:声卡,显卡,数据库 我们的程序会通过 数据库 驱动和数据库打交道 10.2 JDBC SUN公司为了简化 开发人员的(对数据库的统一)操作,提供了一个(Java操作数据 ...
- Java的JDBC
第一个JDBC程序 创建测试数据库 CREATE DATABASE jdbcStudy CHARACTER SET utf8 COLLATE utf8_general_ci; USE jdbcStud ...
- MySQL入门学习day3随笔3
JDBC 数据库驱动 我们的程序会通过数据库驱动和数据库打交道 JDBC Sun公司简化开发人员的操作,提供的规范 第一个JDBC项目 创建一个Java项目 导入jar包 编写测试代码 1 creat ...
- MySQL中interactive_timeout和wait_timeout的区别
在用mysql客户端对数据库进行操作时,打开终端窗口,如果一段时间没有操作,再次操作时,常常会报如下错误: ERROR (HY000): Lost connection to MySQL server ...
- jdbc java数据库连接 4)PreParedStatement接口 之 区别和例子
Statement 和 PreparedStatement 的区别: 1)语句不同 PreparedStatement需要预编译以及需要参数 2)由于PreparedStatement有缓存区,所以效 ...
- JDBC ODBC区别
一.JDBC(Java DataBase Connectivity standard) 1.JDBC,它是一个面向对象的应用程序接口(API), 通过它可访问各类关系数据库. 2. 驱动程序(JDBC ...
- oracle的oci和thin区别(数据源)
我是今天看到tomcat数据源的配置时,想起来这个问题,刚开始还不晓得thin是什么东西! database.url=jdbc:oracle:thin:angel/oracle@192.168.55. ...
- prepareStatement与Statement的区别
prepareStatement与Statement的区别 1.区别: 转 http://blog.csdn.net/zsm653983/article/details/7296609 stmt=co ...
随机推荐
- BZOJ 1878 HH的项链
不能分块(显然复杂度会炸啊.....) 离线+BIT.每个颜色在每个询问中只出现一次. #include<iostream> #include<cstdio> #include ...
- (转)每天一个Linux命令(8): tar
通过SSH访问服务器,难免会要用到压缩,解压缩,打包,解包等,这时候tar命令就是是必不可少的一个功能强大的工具.linux中最流行的tar是麻雀虽小,五脏俱全,功能强大. tar命令可以为linux ...
- 《C和指针》读书笔记 第2章-基本概念
原创文章,转载请注明出处:http://www.cnblogs.com/DayByDay/p/3936485.html
- c# is和as的区别
关于类型的判断和转换有is和as这2个操作符.具体区别和用法如下is就是处于对类型的判断.返回true和false.如果一个对象是某个类型或是其父类型的话就返回为true,否则的话就会返回为false ...
- Redis 主从 Replication 的配置,主从复制原理
概述 Redis的replication机制允许slave从master那里通过网络传输拷贝到完整的数据备份.具有以下特点: 异步复制.从2.8版本开始,slave能不时地从master那里获取到数据 ...
- Java读取excel指定sheet中的各行数据,存入二维数组,包括首行,并打印
1. 读取 //读取excel指定sheet中的各行数据,存入二维数组,包括首行 public static String[][] getSheetData(XSSFSheet sheet) thro ...
- robotframework学习
下载地址: https://pypi.python.org/pypi/robotframework Installation If you already have Python with pip i ...
- 2016年JavaScript技术栈展望
如果你正在筹划新的前端项目或者重构现有项目,那么你需要认识到现在的前端开发环境已经今非昔比,这其中有太多的选择了:React.Flux.Angular.Aurelia.Mocha.Jasmine.Ba ...
- 求相同号码一天内的上网流量——mapreduce
上网数据 1363157985066 13726230503 00-FD-07-A4-72-B8:CMCC 120.196.100.82 i02.c.aliimg.com 24 27 2481 246 ...
- Shell Scipt 命令行带参数,输出log
命令行带参数,以及字符串参数放到ssh命令里可以这么放: #!/bin/bash 这行保证运行bash可以这样: ./data.sh if [ $# != 4 ]; then echo ...