jdk/src/share/classes/java/sql/DriverManager.java
changeset 15278 e081d3f73b75
parent 14174 74a7d8795c22
child 16887 b7c122a88eed
equal deleted inserted replaced
15277:245068ba31b3 15278:e081d3f73b75
     1 /*
     1 /*
     2  * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   170 
   170 
   171     /**
   171     /**
   172      * Attempts to establish a connection to the given database URL.
   172      * Attempts to establish a connection to the given database URL.
   173      * The <code>DriverManager</code> attempts to select an appropriate driver from
   173      * The <code>DriverManager</code> attempts to select an appropriate driver from
   174      * the set of registered JDBC drivers.
   174      * the set of registered JDBC drivers.
       
   175      *<p>
       
   176      * <B>Note:</B> If a property is specified as part of the {@code url} and
       
   177      * is also specified in the {@code Properties} object, it is
       
   178      * implementation-defined as to which value will take precedence.
       
   179      * For maximum portability, an application should only specify a
       
   180      * property once.
   175      *
   181      *
   176      * @param url a database url of the form
   182      * @param url a database url of the form
   177      * <code> jdbc:<em>subprotocol</em>:<em>subname</em></code>
   183      * <code> jdbc:<em>subprotocol</em>:<em>subname</em></code>
   178      * @param info a list of arbitrary string tag/value pairs as
   184      * @param info a list of arbitrary string tag/value pairs as
   179      * connection arguments; normally at least a "user" and
   185      * connection arguments; normally at least a "user" and
   180      * "password" property should be included
   186      * "password" property should be included
   181      * @return a Connection to the URL
   187      * @return a Connection to the URL
   182      * @exception SQLException if a database access error occurs
   188      * @exception SQLException if a database access error occurs or the url is
       
   189      * {@code null}
       
   190      * @throws SQLTimeoutException  when the driver has determined that the
       
   191      * timeout value specified by the {@code setLoginTimeout} method
       
   192      * has been exceeded and has at least tried to cancel the
       
   193      * current database connection attempt
   183      */
   194      */
   184     public static Connection getConnection(String url,
   195     public static Connection getConnection(String url,
   185         java.util.Properties info) throws SQLException {
   196         java.util.Properties info) throws SQLException {
   186 
   197 
   187         // Gets the classloader of the code that called this method, may
   198         // Gets the classloader of the code that called this method, may
   193 
   204 
   194     /**
   205     /**
   195      * Attempts to establish a connection to the given database URL.
   206      * Attempts to establish a connection to the given database URL.
   196      * The <code>DriverManager</code> attempts to select an appropriate driver from
   207      * The <code>DriverManager</code> attempts to select an appropriate driver from
   197      * the set of registered JDBC drivers.
   208      * the set of registered JDBC drivers.
       
   209      *<p>
       
   210      * <B>Note:</B> If a property is specified as part of the {@code url} and
       
   211      * is also specified in the {@code Properties} object, it is
       
   212      * implementation-defined as to which value will take precedence.
       
   213      * For maximum portability, an application should only specify a
       
   214      * property once.
   198      *
   215      *
   199      * @param url a database url of the form
   216      * @param url a database url of the form
   200      * <code>jdbc:<em>subprotocol</em>:<em>subname</em></code>
   217      * <code>jdbc:<em>subprotocol</em>:<em>subname</em></code>
   201      * @param user the database user on whose behalf the connection is being
   218      * @param user the database user on whose behalf the connection is being
   202      *   made
   219      *   made
   203      * @param password the user's password
   220      * @param password the user's password
   204      * @return a connection to the URL
   221      * @return a connection to the URL
   205      * @exception SQLException if a database access error occurs
   222      * @exception SQLException if a database access error occurs or the url is
       
   223      * {@code null}
       
   224      * @throws SQLTimeoutException  when the driver has determined that the
       
   225      * timeout value specified by the {@code setLoginTimeout} method
       
   226      * has been exceeded and has at least tried to cancel the
       
   227      * current database connection attempt
   206      */
   228      */
   207     public static Connection getConnection(String url,
   229     public static Connection getConnection(String url,
   208         String user, String password) throws SQLException {
   230         String user, String password) throws SQLException {
   209         java.util.Properties info = new java.util.Properties();
   231         java.util.Properties info = new java.util.Properties();
   210 
   232 
   228      * the set of registered JDBC drivers.
   250      * the set of registered JDBC drivers.
   229      *
   251      *
   230      * @param url a database url of the form
   252      * @param url a database url of the form
   231      *  <code> jdbc:<em>subprotocol</em>:<em>subname</em></code>
   253      *  <code> jdbc:<em>subprotocol</em>:<em>subname</em></code>
   232      * @return a connection to the URL
   254      * @return a connection to the URL
   233      * @exception SQLException if a database access error occurs
   255      * @exception SQLException if a database access error occurs or the url is
       
   256      * {@code null}
       
   257      * @throws SQLTimeoutException  when the driver has determined that the
       
   258      * timeout value specified by the {@code setLoginTimeout} method
       
   259      * has been exceeded and has at least tried to cancel the
       
   260      * current database connection attempt
   234      */
   261      */
   235     public static Connection getConnection(String url)
   262     public static Connection getConnection(String url)
   236         throws SQLException {
   263         throws SQLException {
   237 
   264 
   238         java.util.Properties info = new java.util.Properties();
   265         java.util.Properties info = new java.util.Properties();
   378     }
   405     }
   379 
   406 
   380 
   407 
   381     /**
   408     /**
   382      * Sets the maximum time in seconds that a driver will wait
   409      * Sets the maximum time in seconds that a driver will wait
   383      * while attempting to connect to a database.
   410      * while attempting to connect to a database once the driver has
       
   411      * been identified.
   384      *
   412      *
   385      * @param seconds the login time limit in seconds; zero means there is no limit
   413      * @param seconds the login time limit in seconds; zero means there is no limit
   386      * @see #getLoginTimeout
   414      * @see #getLoginTimeout
   387      */
   415      */
   388     public static void setLoginTimeout(int seconds) {
   416     public static void setLoginTimeout(int seconds) {