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 区别的更多相关文章

  1. MySql学习笔记--详细整理--下

    目录 索引 测试索引 索引原则 权限管理和备份 备份 规范数据库设计 三大范式 JDBC JDBC程序 Statement对象 工具类实现 sql注入 PreparedStatement对象 事务 数 ...

  2. (十)JDBC(重点)

    10.1  数据库驱动 驱动:声卡,显卡,数据库 我们的程序会通过 数据库 驱动和数据库打交道 10.2  JDBC SUN公司为了简化 开发人员的(对数据库的统一)操作,提供了一个(Java操作数据 ...

  3. Java的JDBC

    第一个JDBC程序 创建测试数据库 CREATE DATABASE jdbcStudy CHARACTER SET utf8 COLLATE utf8_general_ci; USE jdbcStud ...

  4. MySQL入门学习day3随笔3

    JDBC 数据库驱动 我们的程序会通过数据库驱动和数据库打交道 JDBC Sun公司简化开发人员的操作,提供的规范 第一个JDBC项目 创建一个Java项目 导入jar包 编写测试代码 1 creat ...

  5. MySQL中interactive_timeout和wait_timeout的区别

    在用mysql客户端对数据库进行操作时,打开终端窗口,如果一段时间没有操作,再次操作时,常常会报如下错误: ERROR (HY000): Lost connection to MySQL server ...

  6. jdbc java数据库连接 4)PreParedStatement接口 之 区别和例子

    Statement 和 PreparedStatement 的区别: 1)语句不同 PreparedStatement需要预编译以及需要参数 2)由于PreparedStatement有缓存区,所以效 ...

  7. JDBC ODBC区别

    一.JDBC(Java DataBase Connectivity standard) 1.JDBC,它是一个面向对象的应用程序接口(API), 通过它可访问各类关系数据库. 2. 驱动程序(JDBC ...

  8. oracle的oci和thin区别(数据源)

    我是今天看到tomcat数据源的配置时,想起来这个问题,刚开始还不晓得thin是什么东西! database.url=jdbc:oracle:thin:angel/oracle@192.168.55. ...

  9. prepareStatement与Statement的区别

    prepareStatement与Statement的区别 1.区别: 转 http://blog.csdn.net/zsm653983/article/details/7296609 stmt=co ...

随机推荐

  1. setTimeOut() 和 setTimeInterval()

    setTimeOut()は.指定された時間「待ってから」指定された動作を行う関数です.setTimeOut():等待指定时间,执行指定方法. setTimeInterval()は.指定された時間「間隔 ...

  2. 【英语】Bingo口语笔记(31) - Bring系列

    bring up 表示在哪长大 要用被动形式 BYOB 请自带酒瓶

  3. python工厂方式创建list

    >>> l = list('sdfsdf') >>> l ['s', 'd', 'f', 's', 'd', 'f']

  4. 计算机网络——TCP三次、四次握手详解

    三次握手:建立TCP连接 连接建立过程: B的TCP服务器进程先创建传输控制块TCB(存储了每一个连接中的一些重要信息,如:TCP连接表,到发送和接收缓存的指针,到重传队列的指针,当前的发送和接收序号 ...

  5. 【转】VMware 11安装Mac OS X 10.10

    VM11安装Mac OS X 10.10 网上竟没有搜到相似的内容,所以拿出来大家分享 工具/原料 1.VMware Workstation 11 2.unlocker 203(for OS X 插件 ...

  6. 你能识别这些科技公司的真假logo吗?

    快告诉我,不止我一个眼瞎~

  7. myeclipse 10 优化

    一.Myeclipse10修改字体 MyEclipse10是基于Eclipse3.7内核,但在Eclipse的Preferences-〉general-〉 Appearance->Colors ...

  8. MongoDB Auto-Sharding(自动分片)入门介绍

    MongoDB是10gen团队开发的一款面向文档的NoSQL数据库.最近一年多以来,MongoDB被越来越多的大型网站应用到生产环境中,比较著名的有Foursquare, bit.ly, Source ...

  9. Android Application 深入分析

    http://blog.csdn.net/rain_butterfly/article/details/37598939

  10. 创建优雅表格的8个js工具

    当需要呈现数百个表的数据时,展示和可访问性扮演着至关重要的角色.在这种情况下,倘若一个数据网格能够支持大量数据集的HTML Table并提供诸如排序.搜索.过滤和分页等功能,那是棒棒哒.在这篇文章中, ...