Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/sql/DataSource.java
38829 views
/*1* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.sql;2627import java.sql.Connection;28import java.sql.SQLException;29import java.sql.Wrapper;3031/**32* <p>A factory for connections to the physical data source that this33* {@code DataSource} object represents. An alternative to the34* {@code DriverManager} facility, a {@code DataSource} object35* is the preferred means of getting a connection. An object that implements36* the {@code DataSource} interface will typically be37* registered with a naming service based on the38* Java™ Naming and Directory (JNDI) API.39* <P>40* The {@code DataSource} interface is implemented by a driver vendor.41* There are three types of implementations:42* <OL>43* <LI>Basic implementation -- produces a standard {@code Connection}44* object45* <LI>Connection pooling implementation -- produces a {@code Connection}46* object that will automatically participate in connection pooling. This47* implementation works with a middle-tier connection pooling manager.48* <LI>Distributed transaction implementation -- produces a49* {@code Connection} object that may be used for distributed50* transactions and almost always participates in connection pooling.51* This implementation works with a middle-tier52* transaction manager and almost always with a connection53* pooling manager.54* </OL>55* <P>56* A {@code DataSource} object has properties that can be modified57* when necessary. For example, if the data source is moved to a different58* server, the property for the server can be changed. The benefit is that59* because the data source's properties can be changed, any code accessing60* that data source does not need to be changed.61* <P>62* A driver that is accessed via a {@code DataSource} object does not63* register itself with the {@code DriverManager}. Rather, a64* {@code DataSource} object is retrieved though a lookup operation65* and then used to create a {@code Connection} object. With a basic66* implementation, the connection obtained through a {@code DataSource}67* object is identical to a connection obtained through the68* {@code DriverManager} facility.69* <p>70* An implementation of {@code DataSource} must include a public no-arg71* constructor.72*73* @since 1.474*/7576public interface DataSource extends CommonDataSource, Wrapper {7778/**79* <p>Attempts to establish a connection with the data source that80* this {@code DataSource} object represents.81*82* @return a connection to the data source83* @exception SQLException if a database access error occurs84* @throws java.sql.SQLTimeoutException when the driver has determined that the85* timeout value specified by the {@code setLoginTimeout} method86* has been exceeded and has at least tried to cancel the87* current database connection attempt88*/89Connection getConnection() throws SQLException;9091/**92* <p>Attempts to establish a connection with the data source that93* this {@code DataSource} object represents.94*95* @param username the database user on whose behalf the connection is96* being made97* @param password the user's password98* @return a connection to the data source99* @exception SQLException if a database access error occurs100* @throws java.sql.SQLTimeoutException when the driver has determined that the101* timeout value specified by the {@code setLoginTimeout} method102* has been exceeded and has at least tried to cancel the103* current database connection attempt104* @since 1.4105*/106Connection getConnection(String username, String password)107throws SQLException;108}109110111