java.sql

Class DriverManager


public class DriverManager
extends Object

The basic service for managing a set of JDBC drivers.
NOTE: The DataSource interface, new in the JDBC 2.0 API, provides another way to connect to a data source. The use of a DataSource object is the preferred means of connecting to a data source.

As part of its initialization, the DriverManager class will attempt to load the driver classes referenced in the "jdbc.drivers" system property. This allows a user to customize the JDBC Drivers used by their applications. For example in your ~/.hotjava/properties file you might specify:

 jdbc.drivers=foo.bah.Driver:wombat.sql.Driver:bad.taste.ourDriver
 
A program can also explicitly load JDBC drivers at any time. For example, the my.sql.Driver is loaded with the following statement:
 Class.forName("my.sql.Driver");
 

When the method getConnection is called, the DriverManager will attempt to locate a suitable driver from amongst those loaded at initialization and those loaded explicitly using the same classloader as the current applet or application.

Starting with the Java 2 SDK, Standard Edition, version 1.3, a logging stream can be set only if the proper permission has been granted. Normally this will be done with the tool PolicyTool, which can be used to grant permission java.sql.SQLPermission "setLog".

See Also:
Driver, Connection

Method Summary

static void
deregisterDriver(Driver driver)
Drops a driver from the DriverManager's list.
static Connection
getConnection(String url)
Attempts to establish a connection to the given database URL.
static Connection
getConnection(String url, String user, String password)
Attempts to establish a connection to the given database URL.
static Connection
getConnection(String url, Properties info)
Attempts to establish a connection to the given database URL.
static Driver
getDriver(String url)
Attempts to locate a driver that understands the given URL.
static java.util.Enumeration
getDrivers()
Retrieves an Enumeration with all of the currently loaded JDBC drivers to which the current caller has access.
static PrintWriter
getLogWriter()
Retrieves the log writer.
static int
getLoginTimeout()
Gets the maximum time in seconds that a driver can wait when attempting to log in to a database.
static @Deprecated
java.io.PrintStream getLogStream()
Deprecated.
static void
println(String message)
Prints a message to the current JDBC log stream.
static void
registerDriver(Driver driver)
Registers the given driver with the DriverManager.
static void
setLogWriter(PrintWriter out)
Sets the logging/tracing PrintWriter object that is used by the DriverManager and all drivers.
static void
setLoginTimeout(int seconds)
Sets the maximum time in seconds that a driver will wait while attempting to connect to a database.
static @Deprecated
void setLogStream(PrintStream out)
Deprecated.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Details

deregisterDriver

public static void deregisterDriver(Driver driver)
            throws SQLException
Drops a driver from the DriverManager's list. Applets can only deregister drivers from their own classloaders.
Parameters:
driver - the JDBC Driver to drop
Throws:
SQLException - if a database access error occurs
Usages and Demos :

View More Examples of deregisterDriver(Driver driver)
   1: import java.sql.Driver;
   2: import java.sql.DriverManager;
   3: import java.sql.SQLException;
   4:         ...
   5: 
   6:         for (Enumeration e = DriverManager.getDrivers(); e.hasMoreElements();)
   7:         {
   8:         ...
   9:                 {
  10:                     DriverManager.deregisterDriver(driver);
  11:                 }

View Full Code Here
   1: import java.sql.Driver;
   2: import java.sql.DriverManager;
   3: import java.sql.SQLException;
   4:         ...
   5:     
   6:     public static void deregisterDriver(Driver driver)    throws SQLException        { DriverManager.deregisterDriver(driver); }
   7:           
   8:         ...
   9:     public static Connection getConnection(String url) throws SQLException        {
  10:         Connection conn = DriverManager.getConnection(url);
  11:         if (conn==null)
  12:         ...
  13:     public static Connection getConnection(String url, Properties info) throws SQLException {
  14:         Connection conn = DriverManager.getConnection(url,info);

View Full Code Here
   1:                 inklingDriver = new ModelCoreDriver();
   2:                 conn = java.sql.DriverManager.getConnection(databaseUrl);
   3: 
   4:         ...
   5:             conn.close();
   6:             java.sql.DriverManager.deregisterDriver(inklingDriver);
   7: 
   8: 
   9:             int count = 0;

View Full Code Here
   1:                 conn.close();
   2:                 java.sql.DriverManager.deregisterDriver(inklingDriver);
   3:             }
   4: 
   5:             return results;

View Full Code Here
   1:             try {
   2:                 conn = java.sql.DriverManager.getConnection(dburl);
   3:                 java.sql.Statement s = conn.createStatement();
   4:         ...
   5:                 Class.forName("org.postgresql.Driver");
   6:                 conn = java.sql.DriverManager.getConnection(
   7:                         jdbcDatabaseUrl);
   8:         ...
   9:             conn.close();
  10:             java.sql.DriverManager.deregisterDriver(driver);

View Full Code Here

getConnection

public static Connection getConnection(String url)
            throws SQLException
Attempts to establish a connection to the given database URL. The DriverManager attempts to select an appropriate driver from the set of registered JDBC drivers.
Parameters:
url - a database url of the form jdbc:subprotocol:subname
Returns:
a connection to the URL
Throws:
SQLException - if a database access error occurs
Usages and Demos :

View More Examples of getConnection(String url)
   1:     Connection c = 
   2:       DriverManager.getConnection("jdbc:odbc:Kurse");
   3:       DatabaseMetaData meta = c.getMetaData();
   4:       System.out.println(meta.getDatabaseProductName() + " " 
   5:                        + meta.getDatabaseProductVersion() );

View Full Code Here
   1: import java.sql.Connection;
   2: import java.sql.DriverManager;
   3: import java.sql.SQLException;
   4:         ...
   5:     protected Connection initConnection() throws SQLException {
   6:         DriverManager.registerDriver(new com.mysql.jdbc.Driver());
   7:     }
   8: 
   9:     protected TableMapping initMapping(Class pClass) throws DAOException {

View Full Code Here
   1: import java.sql.Statement;
   2: import java.sql.DriverManager;
   3: 
   4: import org.apache.commons.beanutils.RowSetDynaClass;

View Full Code Here
   1: import java.sql.Statement;
   2: import java.sql.DriverManager;
   3: 
   4: import org.apache.commons.beanutils.RowSetDynaClass;

View Full Code Here
   1:     returning(Connection connection)
   2:     : call(Connection DBConnectionPool.getConnection(..))
   3:     && args(url, userName, password) {
   4:         ...
   5:     returning(Connection connection)
   6:     : call(Connection DriverManager.getConnection(..))
   7:     && args(url, userName, password) {
   8:     System.out.println("For [" + url + "," + userName
   9:                + "," + password + "]"

View Full Code Here

getConnection

public static Connection getConnection(String url,
                                       String user,
                                       String password)
            throws SQLException
Attempts to establish a connection to the given database URL. The DriverManager attempts to select an appropriate driver from the set of registered JDBC drivers.
Parameters:
url - a database url of the form jdbc:subprotocol:subname
user - the database user on whose behalf the connection is being made
password - the user's password
Returns:
a connection to the URL
Throws:
SQLException - if a database access error occurs
Usages and Demos :

View More Examples of getConnection(String url,String user,String password)
   1:       Class.forName(driver);
   2:       connection=DriverManager.getConnection(dbURL,login,password);
   3:       statement=connection.createStatement();
   4:         ...
   5:         connection =
   6:           DriverManager.getConnection(dbURL,login,password);
   7:         statement = connection.createStatement();
   8:       }
   9:     }

View Full Code Here
   1: 
   2: import java.sql.DriverManager;
   3: import java.sql.SQLException;
   4:         ...
   5:         try {
   6:             DriverManager.getConnection(SHUTDOWN_ALL, null, null);
   7:         } catch (SQLException e) {
   8:         ...
   9:         try {
  10:             DriverManager.getConnection(SHUTDOWN_ALL, null, null);
  11:         } catch (SQLException e) {

View Full Code Here
   1:       String dbPassword = "octopus";
   2:       return DriverManager.getConnection(dbURL, dbUser, dbPassword);
   3:    }
   4: 
   5:    public static void main(String[] args)

View Full Code Here
   1: import java.sql.Connection;
   2: import java.sql.DriverManager;
   3: 
   4:         ...
   5:     private void connect() throws SQLException {
   6:         Connection c = DriverManager.getConnection("jdbc:derby:testdb;create=true");
   7:         c.close();
   8:         ...
   9:         try {
  10:             DriverManager.getConnection(SHUTDOWN_ALL, null, null);
  11:         } catch (SQLException e) {

View Full Code Here
   1: import java.sql.Connection;
   2: import java.sql.DriverManager;
   3: import java.sql.SQLException;
   4:         ...
   5:                 if((_uname == null) || (_passwd == null)) {
   6:                     return DriverManager.getConnection(_connectUri);
   7:                 } else {
   8:         ...
   9:                     return DriverManager.getConnection(_connectUri,_uname,_passwd);
  10:                 }
  11:         ...
  12:             } else {
  13:                 return DriverManager.getConnection(_connectUri,_props);

View Full Code Here

getConnection

public static Connection getConnection(String url,
                                       Properties info)
            throws SQLException
Attempts to establish a connection to the given database URL. The DriverManager attempts to select an appropriate driver from the set of registered JDBC drivers.
Parameters:
url - a database url of the form jdbc:subprotocol:subname
info - a list of arbitrary string tag/value pairs as connection arguments; normally at least a "user" and "password" property should be included
Returns:
a Connection to the URL
Throws:
SQLException - if a database access error occurs
Usages and Demos :

View More Examples of getConnection(String url,java.util.Properties info)
   1: 
   2: public class DriverManager {
   3: 
   4:         ...
   5:     {
   6:             return java.sql.DriverManager.getConnection(url, user, password);
   7:     }
   8:         ...
   9:     {
  10:             return java.sql.DriverManager.getConnection(url, props);
  11:     }
  12:         ...
  13:     {
  14:             return java.sql.DriverManager.getConnection(url);

View Full Code Here
   1: import java.sql.Connection;
   2: import java.sql.DriverManager;
   3: import java.sql.SQLException;
   4:         ...
   5:         Properties info = cpd.getDelegateProperties();
   6:         return DriverManager.getConnection(url, info);
   7:     }
   8: 
   9: }

View Full Code Here
   1:       conn =
   2:            DriverManager.getConnection(POOLPREFIX+poolName, null);
   3:       return EVAL_BODY_TAG;
   4:     } catch(Exception e) {
   5:       throw new JspException("Failed to load JDBC driver: "+DRIVER);

View Full Code Here
   1: import java.sql.SQLException;
   2: import java.sql.DriverManager;
   3: 
   4:         ...
   5:         final Properties info = createBasicProperties(alias);
   6:         DriverManager.getConnection(url, info).close();
   7:         return info;
   8:     }

View Full Code Here
   1: import java.sql.Connection;
   2: import java.sql.DriverManager;
   3: import java.sql.PreparedStatement;
   4:         ...
   5:         _connectionProxy = ConnectionProxyFactory.newConnectionProxy(
   6:                 DriverManager.getConnection(JDBC_URL, properties), getClass().getName());
   7:         
   8:     }
   9:     

View Full Code Here

getDriver

public static Driver getDriver(String url)
            throws SQLException
Attempts to locate a driver that understands the given URL. The DriverManager attempts to select an appropriate driver from the set of registered JDBC drivers.
Parameters:
url - a database URL of the form jdbc:subprotocol:subname
Returns:
a Driver object representing a driver that can connect to the given URL
Throws:
SQLException - if a database access error occurs
Usages and Demos :

View More Examples of getDriver(String url)
   1: import java.sql.Driver;
   2: import java.sql.DriverManager;
   3: import java.sql.SQLException;
   4:         ...
   5:     
   6:     public static void deregisterDriver(Driver driver)    throws SQLException        { DriverManager.deregisterDriver(driver); }
   7:           
   8:         ...
   9:     public static Connection getConnection(String url) throws SQLException        {
  10:         Connection conn = DriverManager.getConnection(url);
  11:         if (conn==null)
  12:         ...
  13:      
  14:     public static Driver getDriver(String url)    throws SQLException            { return DriverManager.getDriver(url); }

View Full Code Here
   1: import java.sql.Connection;
   2: import java.sql.DriverManager;
   3: import java.sql.SQLException;
   4:         ...
   5:         {
   6:             con = DriverManager.getConnection( getPoolUrl() );
   7:         }
   8:         ...
   9:         {
  10:             PoolingDriver driver = (PoolingDriver) DriverManager.getDriver( DRIVER_NAME );
  11:             ObjectPool connectionPool = driver.getConnectionPool( this.getPoolName() );
  12:         ...
  13:         {
  14:             PoolingDriver driver = (PoolingDriver) DriverManager.getDriver( DRIVER_NAME );

View Full Code Here
   1: import java.sql.Connection;
   2: import java.sql.DriverManager;
   3: import java.sql.PreparedStatement;
   4:         ...
   5: 
   6:             conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:infoGlueJDBCPropertySet");
   7:             if(logger.isDebugEnabled())
   8:         ...
   9:         Class.forName("org.apache.commons.dbcp.PoolingDriver");
  10:         driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");
  11: 
  12:         ...
  13:     {
  14:         PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");

View Full Code Here

getDrivers

public static java.util.Enumeration getDrivers()
Retrieves an Enumeration with all of the currently loaded JDBC drivers to which the current caller has access.

Note: The classname of a driver can be found using d.getClass().getName()

Returns:
the list of JDBC Drivers loaded by the caller's class loader
Usages and Demos :

View More Examples of getDrivers()
   1: 
   2:     for ( Enumeration e = DriverManager.getDrivers(); e.hasMoreElements(); )
   3:       System.out.println( e.nextElement().getClass().getName() );
   4:   }
   5: }

View Full Code Here
   1:   {
   2:     DriverManager.setLogWriter( new PrintWriter(System.out) );
   3: 
   4:         ...
   5: 
   6:     for ( Enumeration e = DriverManager.getDrivers(); e.hasMoreElements(); )
   7:       System.out.println( e.nextElement().getClass().getName() );
   8:   }
   9: }

View Full Code Here
   1: import java.sql.Driver;
   2: import java.sql.DriverManager;
   3: import java.sql.SQLException;
   4:         ...
   5: 
   6:         for (Enumeration e = DriverManager.getDrivers(); e.hasMoreElements();)
   7:         {
   8:         ...
   9:                 {
  10:                     DriverManager.deregisterDriver(driver);
  11:                 }

View Full Code Here
   1: import java.sql.Driver;
   2: import java.sql.DriverManager;
   3: import java.sql.SQLException;
   4:         ...
   5:     
   6:     public static void deregisterDriver(Driver driver)    throws SQLException        { DriverManager.deregisterDriver(driver); }
   7:           
   8:         ...
   9:     public static Connection getConnection(String url) throws SQLException        {
  10:         Connection conn = DriverManager.getConnection(url);
  11:         if (conn==null)
  12:         ...
  13:           
  14:     public static Enumeration getDrivers()    throws SQLException                { return DriverManager.getDrivers(); }

View Full Code Here
   1: import java.sql.Driver;
   2: import java.sql.DriverManager;
   3: import java.util.Enumeration;
   4:         ...
   5:       
   6:       Enumeration regDrivers = DriverManager.getDrivers();
   7:       boolean isRegistered = false;
   8:         ...
   9:         {
  10:           DriverManager.registerDriver((Driver)Class.forName(jdbcDriverClass).newInstance()); 
  11:         }

View Full Code Here

getLogWriter

public static PrintWriter getLogWriter()
Retrieves the log writer. The getLogWriter and setLogWriter methods should be used instead of the get/setlogStream methods, which are deprecated.
Returns:
a java.io.PrintWriter object
Since:
1.2
Usages and Demos :

View More Examples of getLogWriter()
   1:   public int getLoginTimeout()throws SQLException{
   2:     return DriverManager.getLoginTimeout();
   3:   } 
   4:         ...
   5:   public PrintWriter getLogWriter()throws SQLException{
   6:     return DriverManager.getLogWriter();
   7:   } 
   8:         ...
   9:   public void setLoginTimeout(int seconds)throws SQLException{
  10:     DriverManager.setLoginTimeout(seconds);
  11:   } 
  12:         ...
  13:   public void setLogWriter(PrintWriter out)throws SQLException{
  14:     DriverManager.setLogWriter(out);

View Full Code Here
   1: import java.sql.Connection;
   2: import java.sql.DriverManager;
   3: import java.sql.SQLException;
   4:         ...
   5:         return user == null 
   6:             ? DriverManager.getConnection(url) 
   7:         ...
   8:             : DriverManager.getConnection(url, user, password);
   9:     }
  10:         ...
  11:     public PrintWriter getLogWriter() throws SQLException {
  12:         return DriverManager.getLogWriter();

View Full Code Here
   1:     String url = "jdbc:oracle:" + getSubname();
   2:     return DriverManager.getConnection(url, userid, password);
   3:   }
   4:         ...
   5:   public int getLoginTimeout() throws SQLException {
   6:     return DriverManager.getLoginTimeout();
   7:   }
   8:         ...
   9:   public PrintWriter getLogWriter() throws SQLException {
  10:     return DriverManager.getLogWriter();
  11:   }
  12:         ...
  13:   public void setLoginTimeout(int timeout) throws SQLException {
  14:     DriverManager.setLoginTimeout(timeout);

View Full Code Here
   1: import java.lang.reflect.Method;
   2: import java.sql.DriverManager;
   3: import java.sql.SQLException;
   4:         ...
   5:         this.cause = cause;
   6:         if ((cause != null) && (DriverManager.getLogWriter() != null)) {
   7:         ...
   8:             DriverManager.getLogWriter().print("Caused by: ");
   9:         ...
  10:             cause.printStackTrace(DriverManager.getLogWriter());

View Full Code Here
   1: import java.sql.Connection;
   2: import java.sql.DriverManager;
   3: import java.sql.SQLException;
   4:         ...
   5:    {
   6:       return DriverManager.getConnection(url);
   7:    }
   8:         ...
   9:    {
  10:       return DriverManager.getConnection(url+";"+params);
  11:    }
  12:         ...
  13:    {
  14:       return DriverManager.getLogWriter();

View Full Code Here

getLoginTimeout

public static int getLoginTimeout()
Gets the maximum time in seconds that a driver can wait when attempting to log in to a database.
Returns:
the driver login time limit in seconds
Usages and Demos :

View More Examples of getLoginTimeout()
   1:   public int getLoginTimeout()throws SQLException{
   2:     return DriverManager.getLoginTimeout();
   3:   } 
   4:         ...
   5:   public PrintWriter getLogWriter()throws SQLException{
   6:     return DriverManager.getLogWriter();
   7:   } 
   8:         ...
   9:   public void setLoginTimeout(int seconds)throws SQLException{
  10:     DriverManager.setLoginTimeout(seconds);
  11:   } 
  12:         ...
  13:   public void setLogWriter(PrintWriter out)throws SQLException{
  14:     DriverManager.setLogWriter(out);

View Full Code Here
   1: import java.sql.Connection;
   2: import java.sql.DriverManager;
   3: import java.sql.SQLException;
   4:         ...
   5:         return user == null 
   6:             ? DriverManager.getConnection(url) 
   7:         ...
   8:             : DriverManager.getConnection(url, user, password);
   9:     }
  10:         ...
  11:     public int getLoginTimeout() throws SQLException {
  12:         return DriverManager.getLoginTimeout();

View Full Code Here
   1:     String url = "jdbc:oracle:" + getSubname();
   2:     return DriverManager.getConnection(url, userid, password);
   3:   }
   4:         ...
   5:   public int getLoginTimeout() throws SQLException {
   6:     return DriverManager.getLoginTimeout();
   7:   }
   8:         ...
   9:   public PrintWriter getLogWriter() throws SQLException {
  10:     return DriverManager.getLogWriter();
  11:   }
  12:         ...
  13:   public void setLoginTimeout(int timeout) throws SQLException {
  14:     DriverManager.setLoginTimeout(timeout);

View Full Code Here
   1:         props.setProperty("password", passWord);
   2:         Connection c = DriverManager.getConnection(dbURL, props);
   3: 
   4:         ...
   5:     public void setLoginTimeout(int seconds) {
   6:         DriverManager.setLoginTimeout(seconds);
   7:     }
   8:         ...
   9:     public int getLoginTimeout() {
  10:         return DriverManager.getLoginTimeout();
  11:     }

View Full Code Here
   1: import java.sql.Driver;
   2: import java.sql.DriverManager;
   3: import java.sql.SQLException;
   4:         ...
   5:     
   6:     public static void deregisterDriver(Driver driver)    throws SQLException        { DriverManager.deregisterDriver(driver); }
   7:           
   8:         ...
   9:     public static Connection getConnection(String url) throws SQLException        {
  10:         Connection conn = DriverManager.getConnection(url);
  11:         if (conn==null)
  12:         ...
  13:           
  14:     public static int getLoginTimeout()    throws SQLException                    { return DriverManager.getLoginTimeout(); }

View Full Code Here

java.io.PrintStream getLogStream

public static @Deprecated java.io.PrintStream getLogStream()

Deprecated.

Retrieves the logging/tracing PrintStream that is used by the DriverManager and all drivers.
Returns:
the logging/tracing PrintStream; if disabled, is null
See Also:
DriverManager

println

public static void println(String message)
Prints a message to the current JDBC log stream.
Parameters:
message - a log or tracing message
Usages and Demos :

View More Examples of println(String message)
   1: 
   2: import java.sql.DriverManager;
   3: import java.sql.SQLException;
   4:         ...
   5:             for (int i = 0; i < notices.length; i++) {
   6:                 DriverManager.println("Notice: " + notices[i]);
   7:             }
   8:         }
   9:         if (null == errorMessage || errorMessage.length() == 0) {

View Full Code Here
   1: 
   2: import java.sql.DriverManager;
   3: import java.sql.ResultSet;
   4:         ...
   5:         } catch (SQLException ex) {
   6:             DriverManager.println(ex.toString());
   7:             return super.getTablePrivileges(catalog, schemaPattern,
   8:                     tableNamePattern);
   9:         }

View Full Code Here
   1: 
   2: import java.sql.DriverManager;
   3: 
   4:         ...
   5: 
   6:                 if (DriverManager.getLogStream() == null) {
   7:         ...
   8:                     System.out.println(mesg.toString());
   9:                 } else {
  10:         ...
  11:                     DriverManager.println(mesg.toString());

View Full Code Here
   1: 
   2: import java.sql.DriverManager;
   3: import java.sql.ResultSet;
   4:         ...
   5:         } catch (SQLException ex) {
   6:             DriverManager.println(ex.toString());
   7:             return super.getImportedKeys(catalog, schema, impTable);
   8:         }
   9:         

View Full Code Here
   1: import java.sql.Connection;
   2: import java.sql.DriverManager;
   3: import java.sql.ResultSet;
   4:         ...
   5:         } catch (SQLException ex) {
   6:             DriverManager.println(ex.toString());
   7:             return super.getTables(catalog,schemaPattern,tableNamePattern,types);
   8:         ...
   9:         } catch (SQLException ex) {
  10:             DriverManager.println(ex.toString());
  11:             return super.getTablePrivileges(catalog,schemaPattern,tableNamePattern);
  12:         ...
  13:         } catch (SQLException ex) {
  14:             DriverManager.println(ex.toString());

View Full Code Here

registerDriver

public static void registerDriver(Driver driver)
            throws SQLException
Registers the given driver with the DriverManager. A newly-loaded driver class should call the method registerDriver to make itself known to the DriverManager.
Parameters:
driver - the new JDBC Driver that is to be registered with the DriverManager
Throws:
SQLException - if a database access error occurs
Usages and Demos :

View More Examples of registerDriver(java.sql.Driver driver)
   1:       Class jdbcDriver=Class.forName(JDBC_DRIVER);
   2:       java.sql.DriverManager.registerDriver((Driver)jdbcDriver.newInstance());
   3:     }catch(Exception e){e.printStackTrace();}
   4:         ...
   5:   public Connection getConnection()throws SQLException{
   6:       Connection con=java.sql.DriverManager.getConnection( DB_URL,DB_USER,DB_PASSWORD);
   7:       return con;
   8:   }
   9: }

View Full Code Here
   1:       Class jdbcDriver=Class.forName(JDBC_DRIVER);
   2:       java.sql.DriverManager.registerDriver((Driver)jdbcDriver.newInstance());
   3:     }catch(Exception e){e.printStackTrace();}
   4:         ...
   5:   public Connection getConnection()throws SQLException{
   6:       Connection con=java.sql.DriverManager.getConnection( DB_URL,DB_USER,DB_PASSWORD);
   7:       return con;
   8:   }
   9: }

View Full Code Here
   1: import java.sql.Driver;
   2: import java.sql.DriverManager;
   3: import java.sql.SQLException;
   4:         ...
   5:         try {
   6:             DriverManager.registerDriver((Driver) cl.newInstance());
   7:         } catch (Exception e) {
   8:         ...
   9:         try {
  10:             return DriverManager.getConnection(url, user, password);
  11:         } catch (SQLException e) {

View Full Code Here
   1:         try {
   2:             DriverManager.registerDriver(TestDBDriver.instance());
   3:         } catch(SQLException e) {
   4:             Logger.error("Unable to register Test DB pool driver!");
   5:             Logger.exception(e);

View Full Code Here
   1: import java.sql.Driver;
   2: import java.sql.DriverManager;
   3: import java.util.Enumeration;
   4:         ...
   5:       
   6:       Enumeration regDrivers = DriverManager.getDrivers();
   7:       boolean isRegistered = false;
   8:         ...
   9:         {
  10:           DriverManager.registerDriver((Driver)Class.forName(jdbcDriverClass).newInstance()); 
  11:         }

View Full Code Here

setLogWriter

public static void setLogWriter(PrintWriter out)
Sets the logging/tracing PrintWriter object that is used by the DriverManager and all drivers.

There is a minor versioning problem created by the introduction of the method setLogWriter. The method setLogWriter cannot create a PrintStream object that will be returned by getLogStream---the Java platform does not provide a backward conversion. As a result, a new application that uses setLogWriter and also uses a JDBC 1.0 driver that uses getLogStream will likely not see debugging information written by that driver.

In the Java 2 SDK, Standard Edition, version 1.3 release, this method checks to see that there is an SQLPermission object before setting the logging stream. If a SecurityManager exists and its checkPermission method denies setting the log writer, this method throws a java.lang.SecurityException.

Parameters:
out - the new logging/tracing PrintStream object; null to disable logging and tracing
Throws:
SecurityException - if a security manager exists and its checkPermission method denies setting the log writer
Since:
1.2
See Also:
SecurityManager.checkPermission, getLogWriter()
Usages and Demos :

View More Examples of setLogWriter(java.io.PrintWriter out)
   1:     try {
   2:       DriverManager
   3:         .println("User Message: No LogWriter. This won't be seen");
   4:         ...
   5:       PrintWriter log = new PrintWriter(System.out, true);
   6:       DriverManager.setLogWriter(log);
   7:         ...
   8:       DriverManager.println("User Message: LogWriter set");
   9: 
  10:         ...
  11:       DriverManager.println("User Message: Loading Driver");

View Full Code Here
   1:   public int getLoginTimeout()throws SQLException{
   2:     return DriverManager.getLoginTimeout();
   3:   } 
   4:         ...
   5:   public PrintWriter getLogWriter()throws SQLException{
   6:     return DriverManager.getLogWriter();
   7:   } 
   8:         ...
   9:   public void setLoginTimeout(int seconds)throws SQLException{
  10:     DriverManager.setLoginTimeout(seconds);
  11:   } 
  12:         ...
  13:   public void setLogWriter(PrintWriter out)throws SQLException{
  14:     DriverManager.setLogWriter(out);

View Full Code Here
   1: import java.sql.Connection;
   2: import java.sql.DriverManager;
   3: import java.sql.SQLException;
   4:         ...
   5:         return user == null 
   6:             ? DriverManager.getConnection(url) 
   7:         ...
   8:             : DriverManager.getConnection(url, user, password);
   9:     }
  10:         ...
  11:     public void setLogWriter(PrintWriter log) throws SQLException {
  12:         DriverManager.setLogWriter(log);

View Full Code Here
   1:         String password = "root";
   2:         return DriverManager.getConnection(url, username, password);
   3:     }
   4:         ...
   5:             PrintWriter pw = new PrintWriter(new FileOutputStream("mysql_debug.txt"));
   6:             DriverManager.setLogWriter(pw);
   7:             conn = getConnection();
   8:             String tableName = args[0];
   9:             System.out.println("tableName="+tableName);

View Full Code Here
   1:     String url = "jdbc:oracle:" + getSubname();
   2:     return DriverManager.getConnection(url, userid, password);
   3:   }
   4:         ...
   5:   public int getLoginTimeout() throws SQLException {
   6:     return DriverManager.getLoginTimeout();
   7:   }
   8:         ...
   9:   public PrintWriter getLogWriter() throws SQLException {
  10:     return DriverManager.getLogWriter();
  11:   }
  12:         ...
  13:   public void setLogWriter(PrintWriter writer) throws SQLException {
  14:     DriverManager.setLogWriter(writer);

View Full Code Here

setLoginTimeout

public static void setLoginTimeout(int seconds)
Sets the maximum time in seconds that a driver will wait while attempting to connect to a database.
Parameters:
seconds - the login time limit in seconds
Usages and Demos :

View More Examples of setLoginTimeout(int seconds)
   1:     try {
   2:       DriverManager
   3:         .println("User Message: No LogWriter. This won't be seen");
   4:         ...
   5:       PrintWriter log = new PrintWriter(System.out, true);
   6:       DriverManager.setLogWriter(log);
   7:         ...
   8:       DriverManager.println("User Message: LogWriter set");
   9: 
  10:         ...
  11:       Class.forName("COM.cloudscape.core.JDBCDriver");
  12:       DriverManager.setLoginTimeout(60);

View Full Code Here
   1:   public int getLoginTimeout()throws SQLException{
   2:     return DriverManager.getLoginTimeout();
   3:   } 
   4:         ...
   5:   public PrintWriter getLogWriter()throws SQLException{
   6:     return DriverManager.getLogWriter();
   7:   } 
   8:         ...
   9:   public void setLoginTimeout(int seconds)throws SQLException{
  10:     DriverManager.setLoginTimeout(seconds);
  11:   } 
  12:         ...
  13:   public void setLogWriter(PrintWriter out)throws SQLException{
  14:     DriverManager.setLogWriter(out);

View Full Code Here
   1: import java.sql.Connection;
   2: import java.sql.DriverManager;
   3: import java.sql.SQLException;
   4:         ...
   5:         return user == null 
   6:             ? DriverManager.getConnection(url) 
   7:         ...
   8:             : DriverManager.getConnection(url, user, password);
   9:     }
  10:         ...
  11:     public void setLoginTimeout(int timeout) throws SQLException {
  12:         DriverManager.setLoginTimeout(timeout);

View Full Code Here
   1:     String url = "jdbc:oracle:" + getSubname();
   2:     return DriverManager.getConnection(url, userid, password);
   3:   }
   4:         ...
   5:   public int getLoginTimeout() throws SQLException {
   6:     return DriverManager.getLoginTimeout();
   7:   }
   8:         ...
   9:   public PrintWriter getLogWriter() throws SQLException {
  10:     return DriverManager.getLogWriter();
  11:   }
  12:         ...
  13:   public void setLoginTimeout(int timeout) throws SQLException {
  14:     DriverManager.setLoginTimeout(timeout);

View Full Code Here
   1:         props.setProperty("password", passWord);
   2:         Connection c = DriverManager.getConnection(dbURL, props);
   3: 
   4:         ...
   5:     public void setLoginTimeout(int seconds) {
   6:         DriverManager.setLoginTimeout(seconds);
   7:     }
   8:         ...
   9:     public int getLoginTimeout() {
  10:         return DriverManager.getLoginTimeout();
  11:     }

View Full Code Here

void setLogStream

public static @Deprecated void setLogStream(PrintStream out)

Deprecated.

Sets the logging/tracing PrintStream that is used by the DriverManager and all drivers.

In the Java 2 SDK, Standard Edition, version 1.3 release, this method checks to see that there is an SQLPermission object before setting the logging stream. If a SecurityManager exists and its checkPermission method denies setting the log writer, this method throws a java.lang.SecurityException.

Parameters:
out - the new logging/tracing PrintStream; to disable, set to null
Throws:
SecurityException - if a security manager exists and its checkPermission method denies setting the log stream
See Also:
SecurityManager.checkPermission, DriverManager