1 /*
2  * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package javax.sql;
27 
28 import java.sql.Connection;
29 import java.sql.SQLException;
30 import java.sql.Wrapper;
31 
32 /**
33  * <p>A factory for connections to the physical data source that this
34  * <code>DataSource</code> object represents.  An alternative to the
35  * <code>DriverManager</code> facility, a <code>DataSource</code> object
36  * is the preferred means of getting a connection. An object that implements
37  * the <code>DataSource</code> interface will typically be
38  * registered with a naming service based on the
39  * Java<sup><font size=-2>TM</font></sup> Naming and Directory (JNDI) API.
40  * <P>
41  * The <code>DataSource</code> interface is implemented by a driver vendor.
42  * There are three types of implementations:
43  * <OL>
44  *   <LI>Basic implementation -- produces a standard <code>Connection</code>
45  *       object
46  *   <LI>Connection pooling implementation -- produces a <code>Connection</code>
47  *       object that will automatically participate in connection pooling.  This
48  *       implementation works with a middle-tier connection pooling manager.
49  *   <LI>Distributed transaction implementation -- produces a
50  *       <code>Connection</code> object that may be used for distributed
51  *       transactions and almost always participates in connection pooling.
52  *       This implementation works with a middle-tier
53  *       transaction manager and almost always with a connection
54  *       pooling manager.
55  * </OL>
56  * <P>
57  * A <code>DataSource</code> object has properties that can be modified
58  * when necessary.  For example, if the data source is moved to a different
59  * server, the property for the server can be changed.  The benefit is that
60  * because the data source's properties can be changed, any code accessing
61  * that data source does not need to be changed.
62  * <P>
63  * A driver that is accessed via a <code>DataSource</code> object does not
64  * register itself with the <code>DriverManager</code>.  Rather, a
65  * <code>DataSource</code> object is retrieved though a lookup operation
66  * and then used to create a <code>Connection</code> object.  With a basic
67  * implementation, the connection obtained through a <code>DataSource</code>
68  * object is identical to a connection obtained through the
69  * <code>DriverManager</code> facility.
70  *
71  * @since 1.4
72  */
73 
74 public interface DataSource  extends CommonDataSource,Wrapper {
75 
76   /**
77    * <p>Attempts to establish a connection with the data source that
78    * this <code>DataSource</code> object represents.
79    *
80    * @return  a connection to the data source
81    * @exception SQLException if a database access error occurs
82    */
getConnection()83   Connection getConnection() throws SQLException;
84 
85   /**
86    * <p>Attempts to establish a connection with the data source that
87    * this <code>DataSource</code> object represents.
88    *
89    * @param username the database user on whose behalf the connection is
90    *  being made
91    * @param password the user's password
92    * @return  a connection to the data source
93    * @exception SQLException if a database access error occurs
94    * @since 1.4
95    */
getConnection(String username, String password)96   Connection getConnection(String username, String password)
97     throws SQLException;
98 
99 }
100