jdk/src/share/classes/java/sql/DriverManager.java
author lancea
Tue, 09 Oct 2012 08:58:27 -0400
changeset 14171 94eb36844bd7
parent 13660 bf59eb142ae2
child 14174 74a7d8795c22
permissions -rw-r--r--
7197395: Add @Deprecated to all deprecated methods to eliminate compiler warnings in JDBC Reviewed-by: alanb, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
12885
30a5ef357cf1 7172551: Remove Native calls from DriverManager for jigsaw
lancea
parents: 11129
diff changeset
     2
 * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.sql;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.ServiceLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.PrivilegedAction;
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
    32
import java.util.concurrent.CopyOnWriteArrayList;
12885
30a5ef357cf1 7172551: Remove Native calls from DriverManager for jigsaw
lancea
parents: 11129
diff changeset
    33
import sun.reflect.Reflection;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <P>The basic service for managing a set of JDBC drivers.<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <B>NOTE:</B> The {@link <code>DataSource</code>} interface, new in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * JDBC 2.0 API, provides another way to connect to a data source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * The use of a <code>DataSource</code> object is the preferred means of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * connecting to a data source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <P>As part of its initialization, the <code>DriverManager</code> class will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * attempt to load the driver classes referenced in the "jdbc.drivers"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * system property. This allows a user to customize the JDBC Drivers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * used by their applications. For example in your
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * ~/.hotjava/properties file you might specify:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <CODE>jdbc.drivers=foo.bah.Driver:wombat.sql.Driver:bad.taste.ourDriver</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *<P> The <code>DriverManager</code> methods <code>getConnection</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <code>getDrivers</code> have been enhanced to support the Java Standard Edition
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <a href="../../../technotes/guides/jar/jar.html#Service%20Provider">Service Provider</a> mechanism. JDBC 4.0 Drivers must
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * include the file <code>META-INF/services/java.sql.Driver</code>. This file contains the name of the JDBC drivers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * implementation of <code>java.sql.Driver</code>.  For example, to load the <code>my.sql.Driver</code> class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * the <code>META-INF/services/java.sql.Driver</code> file would contain the entry:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <code>my.sql.Driver</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <P>Applications no longer need to explictly load JDBC drivers using <code>Class.forName()</code>. Existing programs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * which currently load JDBC drivers using <code>Class.forName()</code> will continue to work without
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * modification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <P>When the method <code>getConnection</code> is called,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * the <code>DriverManager</code> will attempt to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * locate a suitable driver from amongst those loaded at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * initialization and those loaded explicitly using the same classloader
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * as the current applet or application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * Starting with the Java 2 SDK, Standard Edition, version 1.3, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * logging stream can be set only if the proper
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * permission has been granted.  Normally this will be done with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * the tool PolicyTool, which can be used to grant <code>permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * java.sql.SQLPermission "setLog"</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * @see Driver
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * @see Connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
public class DriverManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
    83
    // List of registered JDBC drivers
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9243
diff changeset
    84
    private final static CopyOnWriteArrayList<DriverInfo> registeredDrivers = new CopyOnWriteArrayList<>();
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
    85
    private static volatile int loginTimeout = 0;
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
    86
    private static volatile java.io.PrintWriter logWriter = null;
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
    87
    private static volatile java.io.PrintStream logStream = null;
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
    88
    // Used in println() to synchronize logWriter
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
    89
    private final static  Object logSync = new Object();
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
    90
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
    91
    /* Prevent the DriverManager class from being instantiated. */
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
    92
    private DriverManager(){}
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
    93
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
    94
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
    95
    /**
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
    96
     * Load the initial JDBC drivers by checking the System property
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
    97
     * jdbc.properties and then use the {@code ServiceLoader} mechanism
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
    98
     */
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
    99
    static {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   100
        loadInitialDrivers();
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   101
        println("JDBC DriverManager initialized");
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   102
    }
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   103
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * The <code>SQLPermission</code> constant that allows the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * setting of the logging stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    final static SQLPermission SET_LOG_PERMISSION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        new SQLPermission("setLog");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    //--------------------------JDBC 2.0-----------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Retrieves the log writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * The <code>getLogWriter</code> and <code>setLogWriter</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * methods should be used instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * of the <code>get/setlogStream</code> methods, which are deprecated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @return a <code>java.io.PrintWriter</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @see #setLogWriter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public static java.io.PrintWriter getLogWriter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            return logWriter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Sets the logging/tracing <code>PrintWriter</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * that is used by the <code>DriverManager</code> and all drivers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * There is a minor versioning problem created by the introduction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * of the method <code>setLogWriter</code>.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * method <code>setLogWriter</code> cannot create a <code>PrintStream</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * that will be returned by <code>getLogStream</code>---the Java platform does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * not provide a backward conversion.  As a result, a new application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * that uses <code>setLogWriter</code> and also uses a JDBC 1.0 driver that uses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * <code>getLogStream</code> will likely not see debugging information written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * by that driver.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Starting with the Java 2 SDK, Standard Edition, version 1.3 release, this method checks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * to see that there is an <code>SQLPermission</code> object before setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * the logging stream.  If a <code>SecurityManager</code> exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * <code>checkPermission</code> method denies setting the log writer, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * method throws a <code>java.lang.SecurityException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @param out the new logging/tracing <code>PrintStream</code> object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *      <code>null</code> to disable logging and tracing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @throws SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *    if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *    <code>checkPermission</code> method denies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *    setting the log writer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @see SecurityManager#checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @see #getLogWriter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public static void setLogWriter(java.io.PrintWriter out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        SecurityManager sec = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        if (sec != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            sec.checkPermission(SET_LOG_PERMISSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            logStream = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            logWriter = out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    //---------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * Attempts to establish a connection to the given database URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * The <code>DriverManager</code> attempts to select an appropriate driver from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * the set of registered JDBC drivers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @param url a database url of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * <code> jdbc:<em>subprotocol</em>:<em>subname</em></code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @param info a list of arbitrary string tag/value pairs as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * connection arguments; normally at least a "user" and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * "password" property should be included
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @return a Connection to the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @exception SQLException if a database access error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public static Connection getConnection(String url,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        java.util.Properties info) throws SQLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        // Gets the classloader of the code that called this method, may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        // be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        ClassLoader callerCL = DriverManager.getCallerClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        return (getConnection(url, info, callerCL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Attempts to establish a connection to the given database URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * The <code>DriverManager</code> attempts to select an appropriate driver from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * the set of registered JDBC drivers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @param url a database url of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * <code>jdbc:<em>subprotocol</em>:<em>subname</em></code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @param user the database user on whose behalf the connection is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *   made
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @param password the user's password
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @return a connection to the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @exception SQLException if a database access error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public static Connection getConnection(String url,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        String user, String password) throws SQLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        java.util.Properties info = new java.util.Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        // Gets the classloader of the code that called this method, may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        // be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        ClassLoader callerCL = DriverManager.getCallerClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        if (user != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            info.put("user", user);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (password != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            info.put("password", password);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        return (getConnection(url, info, callerCL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * Attempts to establish a connection to the given database URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * The <code>DriverManager</code> attempts to select an appropriate driver from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * the set of registered JDBC drivers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @param url a database url of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *  <code> jdbc:<em>subprotocol</em>:<em>subname</em></code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @return a connection to the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @exception SQLException if a database access error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public static Connection getConnection(String url)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        throws SQLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        java.util.Properties info = new java.util.Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        // Gets the classloader of the code that called this method, may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        // be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        ClassLoader callerCL = DriverManager.getCallerClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        return (getConnection(url, info, callerCL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * Attempts to locate a driver that understands the given URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * The <code>DriverManager</code> attempts to select an appropriate driver from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * the set of registered JDBC drivers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @param url a database URL of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *     <code>jdbc:<em>subprotocol</em>:<em>subname</em></code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @return a <code>Driver</code> object representing a driver
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * that can connect to the given URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @exception SQLException if a database access error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    public static Driver getDriver(String url)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        throws SQLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        println("DriverManager.getDriver(\"" + url + "\")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        // Gets the classloader of the code that called this method, may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        // be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        ClassLoader callerCL = DriverManager.getCallerClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   267
        // Walk through the loaded registeredDrivers attempting to locate someone
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        // who understands the given URL.
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   269
        for (DriverInfo aDriver : registeredDrivers) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            // If the caller does not have permission to load the driver then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            // skip it.
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   272
            if(isDriverAllowed(aDriver.driver, callerCL)) {
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   273
                try {
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   274
                    if(aDriver.driver.acceptsURL(url)) {
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   275
                        // Success!
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   276
                        println("getDriver returning " + aDriver.driver.getClass().getName());
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   277
                    return (aDriver.driver);
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   278
                    }
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   279
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   280
                } catch(SQLException sqe) {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   281
                    // Drop through and try the next driver.
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   282
                }
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   283
            } else {
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   284
                println("    skipping: " + aDriver.driver.getClass().getName());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            }
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   286
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        println("getDriver: no suitable driver");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        throw new SQLException("No suitable driver", "08001");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * Registers the given driver with the <code>DriverManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * A newly-loaded driver class should call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * the method <code>registerDriver</code> to make itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * known to the <code>DriverManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @param driver the new JDBC Driver that is to be registered with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *               <code>DriverManager</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @exception SQLException if a database access error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    public static synchronized void registerDriver(java.sql.Driver driver)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        throws SQLException {
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   306
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   307
        /* Register the driver if it has not already been added to our list */
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   308
        if(driver != null) {
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   309
            registeredDrivers.addIfAbsent(new DriverInfo(driver));
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   310
        } else {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   311
            // This is for compatibility with the original DriverManager
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   312
            throw new NullPointerException();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   315
        println("registerDriver: " + driver);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * Drops a driver from the <code>DriverManager</code>'s list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *  Applets can only deregister drivers from their own classloaders.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @param driver the JDBC Driver to drop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @exception SQLException if a database access error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public static synchronized void deregisterDriver(Driver driver)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        throws SQLException {
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   328
        if (driver == null) {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   329
            return;
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   330
        }
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   331
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        // Gets the classloader of the code that called this method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        // may be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        ClassLoader callerCL = DriverManager.getCallerClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        println("DriverManager.deregisterDriver: " + driver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   337
        DriverInfo aDriver = new DriverInfo(driver);
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   338
        if(registeredDrivers.contains(aDriver)) {
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   339
            if (isDriverAllowed(driver, callerCL)) {
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   340
                 registeredDrivers.remove(aDriver);
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   341
            } else {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   342
                // If the caller does not have permission to load the driver then
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   343
                // throw a SecurityException.
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   344
                throw new SecurityException();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            }
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   346
        } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            println("    couldn't find driver to unload");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * Retrieves an Enumeration with all of the currently loaded JDBC drivers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * to which the current caller has access.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * <P><B>Note:</B> The classname of a driver can be found using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * <CODE>d.getClass().getName()</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * @return the list of JDBC Drivers loaded by the caller's class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    public static java.util.Enumeration<Driver> getDrivers() {
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9243
diff changeset
   361
        java.util.Vector<Driver> result = new java.util.Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        // Gets the classloader of the code that called this method, may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        // be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        ClassLoader callerCL = DriverManager.getCallerClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   367
        // Walk through the loaded registeredDrivers.
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   368
        for(DriverInfo aDriver : registeredDrivers) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            // If the caller does not have permission to load the driver then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            // skip it.
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   371
            if(isDriverAllowed(aDriver.driver, callerCL)) {
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   372
                result.addElement(aDriver.driver);
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   373
            } else {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   374
                println("    skipping: " + aDriver.getClass().getName());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        return (result.elements());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * Sets the maximum time in seconds that a driver will wait
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * while attempting to connect to a database.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * @param seconds the login time limit in seconds; zero means there is no limit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * @see #getLoginTimeout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    public static void setLoginTimeout(int seconds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        loginTimeout = seconds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * Gets the maximum time in seconds that a driver can wait
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * when attempting to log in to a database.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @return the driver login time limit in seconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @see #setLoginTimeout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    public static int getLoginTimeout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        return (loginTimeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * Sets the logging/tracing PrintStream that is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * by the <code>DriverManager</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * and all drivers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     *<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * In the Java 2 SDK, Standard Edition, version 1.3 release, this method checks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * to see that there is an <code>SQLPermission</code> object before setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * the logging stream.  If a <code>SecurityManager</code> exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * <code>checkPermission</code> method denies setting the log writer, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * method throws a <code>java.lang.SecurityException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @param out the new logging/tracing PrintStream; to disable, set to <code>null</code>
14171
94eb36844bd7 7197395: Add @Deprecated to all deprecated methods to eliminate compiler warnings in JDBC
lancea
parents: 13660
diff changeset
   415
     * @deprecated Use {@code setLogWriter)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @throws SecurityException if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *    <code>checkPermission</code> method denies setting the log stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @see SecurityManager#checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @see #getLogStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     */
14171
94eb36844bd7 7197395: Add @Deprecated to all deprecated methods to eliminate compiler warnings in JDBC
lancea
parents: 13660
diff changeset
   422
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    public static void setLogStream(java.io.PrintStream out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        SecurityManager sec = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        if (sec != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            sec.checkPermission(SET_LOG_PERMISSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        logStream = out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        if ( out != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            logWriter = new java.io.PrintWriter(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            logWriter = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * Retrieves the logging/tracing PrintStream that is used by the <code>DriverManager</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * and all drivers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * @return the logging/tracing PrintStream; if disabled, is <code>null</code>
14171
94eb36844bd7 7197395: Add @Deprecated to all deprecated methods to eliminate compiler warnings in JDBC
lancea
parents: 13660
diff changeset
   442
     * @deprecated  Use {@code getLogWriter)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * @see #setLogStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     */
14171
94eb36844bd7 7197395: Add @Deprecated to all deprecated methods to eliminate compiler warnings in JDBC
lancea
parents: 13660
diff changeset
   445
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    public static java.io.PrintStream getLogStream() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        return logStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * Prints a message to the current JDBC log stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * @param message a log or tracing message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    public static void println(String message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        synchronized (logSync) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            if (logWriter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                logWriter.println(message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                // automatic flushing is never enabled, so we must do it ourselves
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                logWriter.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    //------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
12885
30a5ef357cf1 7172551: Remove Native calls from DriverManager for jigsaw
lancea
parents: 11129
diff changeset
   468
    // Internal method used to get the caller's class loader.
30a5ef357cf1 7172551: Remove Native calls from DriverManager for jigsaw
lancea
parents: 11129
diff changeset
   469
    // Replaces the call to the native method
30a5ef357cf1 7172551: Remove Native calls from DriverManager for jigsaw
lancea
parents: 11129
diff changeset
   470
    private static ClassLoader getCallerClassLoader() {
30a5ef357cf1 7172551: Remove Native calls from DriverManager for jigsaw
lancea
parents: 11129
diff changeset
   471
        Class<?> cc = Reflection.getCallerClass(3);
30a5ef357cf1 7172551: Remove Native calls from DriverManager for jigsaw
lancea
parents: 11129
diff changeset
   472
        ClassLoader cl = (cc != null) ? cc.getClassLoader() : null;
30a5ef357cf1 7172551: Remove Native calls from DriverManager for jigsaw
lancea
parents: 11129
diff changeset
   473
        return cl;
30a5ef357cf1 7172551: Remove Native calls from DriverManager for jigsaw
lancea
parents: 11129
diff changeset
   474
    }
30a5ef357cf1 7172551: Remove Native calls from DriverManager for jigsaw
lancea
parents: 11129
diff changeset
   475
30a5ef357cf1 7172551: Remove Native calls from DriverManager for jigsaw
lancea
parents: 11129
diff changeset
   476
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   477
    // Indicates whether the class object that would be created if the code calling
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   478
    // DriverManager is accessible.
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   479
    private static boolean isDriverAllowed(Driver driver, ClassLoader classLoader) {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   480
        boolean result = false;
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   481
        if(driver != null) {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   482
            Class<?> aClass = null;
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   483
            try {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   484
                aClass =  Class.forName(driver.getClass().getName(), true, classLoader);
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   485
            } catch (Exception ex) {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   486
                result = false;
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   487
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   489
             result = ( aClass == driver.getClass() ) ? true : false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   492
        return result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    private static void loadInitialDrivers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        String drivers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        try {
9243
d7a77bce0742 7034656: Address lint warnings for DriverManager
lancea
parents: 9239
diff changeset
   498
            drivers = AccessController.doPrivileged(new PrivilegedAction<String>() {
d7a77bce0742 7034656: Address lint warnings for DriverManager
lancea
parents: 9239
diff changeset
   499
                public String run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                    return System.getProperty("jdbc.drivers");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            drivers = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        // If the driver is packaged as a Service Provider, load it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        // Get all the drivers through the classloader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        // exposed as a java.sql.Driver.class service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        // ServiceLoader.load() replaces the sun.misc.Providers()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
9243
d7a77bce0742 7034656: Address lint warnings for DriverManager
lancea
parents: 9239
diff changeset
   511
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
d7a77bce0742 7034656: Address lint warnings for DriverManager
lancea
parents: 9239
diff changeset
   512
            public Void run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                ServiceLoader<Driver> loadedDrivers = ServiceLoader.load(Driver.class);
13660
bf59eb142ae2 7193683: DriverManager Iterator Warning cleanup
lancea
parents: 12885
diff changeset
   515
                Iterator<Driver> driversIterator = loadedDrivers.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                /* Load these drivers, so that they can be instantiated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                 * It may be the case that the driver class may not be there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                 * i.e. there may be a packaged driver with the service class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                 * as implementation of java.sql.Driver but the actual class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                 * may be missing. In that case a java.util.ServiceConfigurationError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                 * will be thrown at runtime by the VM trying to locate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                 * and load the service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                 * Adding a try catch block to catch those runtime errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                 * if driver not available in classpath but it's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                 * packaged as service and that service is there in classpath.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                try{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                    while(driversIterator.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                        println(" Loading done by the java.util.ServiceLoader :  "+driversIterator.next());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                } catch(Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                // Do nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        println("DriverManager.initialize: jdbc.drivers = " + drivers);
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   541
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   542
        if (drivers == null || drivers.equals("")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        }
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   545
        String[] driversList = drivers.split(":");
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   546
        println("number of Drivers:" + driversList.length);
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   547
        for (String aDriver : driversList) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            try {
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   549
                println("DriverManager.Initialize: loading " + aDriver);
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   550
                Class.forName(aDriver, true,
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   551
                        ClassLoader.getSystemClassLoader());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                println("DriverManager.Initialize: load failed: " + ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    //  Worker method called by the public getConnection() methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    private static Connection getConnection(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        String url, java.util.Properties info, ClassLoader callerCL) throws SQLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
         * When callerCl is null, we should check the application's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
         * (which is invoking this class indirectly)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
         * classloader, so that the JDBC driver class outside rt.jar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
         * can be loaded from here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        synchronized(DriverManager.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
          // synchronize loading of the correct classloader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
          if(callerCL == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
              callerCL = Thread.currentThread().getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        if(url == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            throw new SQLException("The url cannot be null", "08001");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        println("DriverManager.getConnection(\"" + url + "\")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   581
        // Walk through the loaded registeredDrivers attempting to make a connection.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        // Remember the first exception that gets raised so we can reraise it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        SQLException reason = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   585
        for(DriverInfo aDriver : registeredDrivers) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            // If the caller does not have permission to load the driver then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            // skip it.
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   588
            if(isDriverAllowed(aDriver.driver, callerCL)) {
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   589
                try {
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   590
                    println("    trying " + aDriver.driver.getClass().getName());
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   591
                    Connection con = aDriver.driver.connect(url, info);
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   592
                    if (con != null) {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   593
                        // Success!
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   594
                        println("getConnection returning " + aDriver.driver.getClass().getName());
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   595
                        return (con);
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   596
                    }
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   597
                } catch (SQLException ex) {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   598
                    if (reason == null) {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   599
                        reason = ex;
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   600
                    }
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   601
                }
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   602
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   603
            } else {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   604
                println("    skipping: " + aDriver.getClass().getName());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            }
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   606
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        // if we got here nobody could connect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        if (reason != null)    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            println("getConnection failed: " + reason);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            throw reason;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        println("getConnection: no suitable driver found for "+ url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        throw new SQLException("No suitable driver found for "+ url, "08001");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
}
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   621
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   622
/*
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   623
 * Wrapper class for registered Drivers in order to not expose Driver.equals()
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   624
 * to avoid the capture of the Driver it being compared to as it might not
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   625
 * normally have access.
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   626
 */
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   627
class DriverInfo {
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   628
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   629
    final Driver driver;
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   630
    DriverInfo(Driver driver) {
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   631
        this.driver = driver;
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   632
    }
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   633
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9243
diff changeset
   634
    @Override
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   635
    public boolean equals(Object other) {
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   636
        return (other instanceof DriverInfo)
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   637
                && this.driver == ((DriverInfo) other).driver;
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   638
    }
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   639
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9243
diff changeset
   640
    @Override
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   641
    public int hashCode() {
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   642
        return driver.hashCode();
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   643
    }
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   644
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9243
diff changeset
   645
    @Override
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   646
    public String toString() {
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   647
        return ("driver[className="  + driver + "]");
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   648
    }
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   649
}