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 ...
随机推荐
- Postgresql两表联结更新
Postgresql两表联合更新近日使用Postgresql感到有点不好用,一个联合更新非要这样写语法才对:update d_routetripset name=b.name , descrip ...
- web.xml整合s2sh内容
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http:// ...
- 部署HBase远程访问的问题集合(Eclipse)
实现远程访问HBase,可以通过Eclipse开发工具方便进行代码调试. 为了方便jar包各种版本的管理,才用maven进行代码构建 首先,下载并安装maven以及M2Eclipse插件 其次,配置m ...
- xsheell的下载安装初级使用
1)关于Xshell 网上更多的资料里提到的SSH客户端是putty,因为简单.开源.免费.但是也正是由于功能过于简单,所以在这里推荐大家使用Xshell. Xshell最初并不能免费使用,而且也没有 ...
- JS面向对象组件(三)--面向对象中的常用属性和方法
图片的由来看下面: 1.hasOwnProperty:看是不是对象自身下面的属性 var arr = []; arr.num = ; Array.prototype.num2 = ; //所有的数组对 ...
- 构建通过 Database.com 提供技术支持的 PhoneGap 应用程序
要求 其他必要产品 Database.com account 用户级别 全部 必需产品 PhoneGap Build 范例文件 Database.Com-PhoneGap-Sample 在这篇文章中, ...
- $(document).Ready()方法 VS OnLoad事件 VS $(window).load()方法
$(document).Ready()方法 VS OnLoad事件 VS $(window).load()方法接触JQuery一般最先学到的是何时启动事件.在曾经很长一段时间里,在页面载入后引发的事件 ...
- hdu 1527 取石子游戏(Wythoff Game)
题意:Wythoff Game 思路:Wythoff Game #include<iostream> #include<stdio.h> #include<math.h& ...
- 第一个UI脚本--python+selenium
之前一直是用java+selenium做自动化测试的,最近因为工作需要,需要用pyhton+selenium去实现,于是就赶驴上架,熟悉了一下python的语法和脚本的编写过程,下面是一个简单的脚本, ...
- 生产环境服务CPU高问题分析
问题描述: 现网个别时候会出现CPU突然飙高的现象,飙高后不能恢复正常. 分析过程: CPU飙高后抓dump,最好本机看,其它机器看dump可能需要下载服务运行机器的sos,clr 0:000 ...