aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/sql/DriverManager.java
diff options
context:
space:
mode:
authorBryce McKinlay <bryce@waitaki.otago.ac.nz>2002-06-21 05:39:33 +0000
committerBryce McKinlay <bryce@gcc.gnu.org>2002-06-21 06:39:33 +0100
commitf2390faddfd8fb109355466b4ba961ef07457006 (patch)
treed61a972368a3bd024fed477ac2ab03e86b96d2f3 /libjava/java/sql/DriverManager.java
parent00b94a4440d95cc009c4434782a00eced71e2745 (diff)
downloadgcc-f2390faddfd8fb109355466b4ba961ef07457006.zip
gcc-f2390faddfd8fb109355466b4ba961ef07457006.tar.gz
gcc-f2390faddfd8fb109355466b4ba961ef07457006.tar.bz2
Reformat JDBC classes and add new JDK 1.4 classes and methods.
* java/sql/ParameterMetaData.java, java/sql/SQLPermission.java, java/sql/Savepoint.java: New files. * java/sql/Array.java, java/sql/BatchUpdateException.java, java/sql/Blob.java, java/sql/CallableStatement.java, java/sql/Clob.java, java/sql/Connection.java, java/sql/DataTruncation.java, java/sql/DatabaseMetaData.java, java/sql/Date.java, java/sql/Driver.java, java/sql/DriverManager.java, java/sql/DriverPropertyInfo.java, java/sql/PreparedStatement.java, java/sql/Ref.java, java/sql/ResultSet.java, java/sql/ResultSetMetaData.java, java/sql/SQLData.java java/sql/SQLException.java, java/sql/SQLInput.java, java/sql/SQLOutput.java, java/sql/SQLWarning.java java/sql/Statement.java, java/sql/Struct.java, java/sql/Time.java, java/sql/Timestamp.java, java/sql/Types.java: Updated to JDBC 3.0 (JDK 1.4) specification. * javax/sql/ConnectionEvent.java, javax/sql/ConnectionEventListener.java, javax/sql/ConnectionPoolDataSource.java, javax/sql/DataSource.java, javax/sql/PooledConnection.java, javax/sql/RowSetEvent.java, javax/sql/RowSetInternal.java, javax/sql/RowSet.java, javax/sql/RowSetListener.java, javax/sql/RowSetMetaData.java, javax/sql/RowSetReader.java, javax/sql/RowSetWriter.java, javax/sql/XAConnection.java, javax/sql/XADataSource.java: New files. * Makefile.am: Add new files. * Makefile.in: Rebuilt. From-SVN: r54871
Diffstat (limited to 'libjava/java/sql/DriverManager.java')
-rw-r--r--libjava/java/sql/DriverManager.java582
1 files changed, 260 insertions, 322 deletions
diff --git a/libjava/java/sql/DriverManager.java b/libjava/java/sql/DriverManager.java
index af6ef12..229450a 100644
--- a/libjava/java/sql/DriverManager.java
+++ b/libjava/java/sql/DriverManager.java
@@ -35,15 +35,14 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package java.sql;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Properties;
-import java.util.StringTokenizer;
import java.util.Vector;
+import java.util.StringTokenizer;
/**
* This class manages the JDBC drivers in the system. It maintains a
@@ -65,341 +64,280 @@ import java.util.Vector;
*/
public class DriverManager
{
-
-/*
- * Class Variables
- */
-
-/**
- * This is the log stream for JDBC drivers.
- */
-private static PrintStream log_stream;
-
-/**
- * This is the log writer for JDBC drivers.
- */
-private static PrintWriter log_writer;
-
-/**
- * This is the login timeout used by JDBC drivers.
- */
-private static int login_timeout;
-
-/**
- * This is the list of JDBC drivers that are loaded.
- */
-private static Vector drivers;
- // Hmm, seems like we might want to do a Hashtable and lookup by something,
- // but what would it be?
-
-// Load all drivers on startup
-static
-{
- drivers = new Vector();
-
- String driver_string = System.getProperty("jdbc.drivers");
- if (driver_string != null)
- {
- StringTokenizer st = new StringTokenizer(driver_string);
- while (st.hasMoreTokens())
- {
- String driver_classname = st.nextToken();
-
- try
- {
- Class.forName(driver_classname); // The driver registers itself
- }
- catch (Exception e) { ; } // Ignore not founds
- }
- }
-
-}
+ /**
+ * This is the log stream for JDBC drivers.
+ */
+ private static PrintStream log_stream;
+
+ /**
+ * This is the log writer for JDBC drivers.
+ */
+ private static PrintWriter log_writer;
+
+ /**
+ * This is the login timeout used by JDBC drivers.
+ */
+ private static int login_timeout;
+
+ /**
+ * This is the list of JDBC drivers that are loaded.
+ */
+ private static Vector drivers;
+ // Hmm, seems like we might want to do a Hashtable and lookup by something,
+ // but what would it be?
+
+ // Load all drivers on startup
+ static
+ {
+ drivers = new Vector();
+
+ String driver_string = System.getProperty("jdbc.drivers");
+ if (driver_string != null)
+ {
+ StringTokenizer st = new StringTokenizer(driver_string);
+ while (st.hasMoreTokens())
+ {
+ String driver_classname = st.nextToken();
+
+ try
+ {
+ Class.forName(driver_classname); // The driver registers itself
+ }
+ catch (Exception e) { ; } // Ignore not founds
+ }
+ }
+
+ }
+
+ /** Can't be instantiated. */
+ private DriverManager()
+ {
+ }
+
+ /**
+ * This method returns the log writer being used by all JDBC drivers.
+ * This method should be used in place of the deprecated
+ * <code>getLogStream</code> method.
+ *
+ * @return The log writer in use by JDBC drivers.
+ */
+ public static PrintWriter getLogWriter()
+ {
+ return log_writer;
+ }
-/*************************************************************************/
-
-/*
- * Class Methods
- */
-
-/**
- * This method returns the login timeout in use by JDBC drivers systemwide.
- *
- * @return The login timeout.
- */
-public static int
-getLoginTimeout()
-{
- return(login_timeout);
-}
-
-/*************************************************************************/
-
-/**
- * This method set the login timeout used by JDBC drivers. This is a
- * system-wide parameter that applies to all drivers.
- *
- * @param login_timeout The new login timeout value.
- */
-public static void
-setLoginTimeout(int login_timeout)
-{
- DriverManager.login_timeout = login_timeout;
-}
-
-/*************************************************************************/
-
-/**
- * This method returns the log writer being used by all JDBC drivers.
- * This method should be used in place of the deprecated
- * <code>getLogStream</code> method.
- *
- * @return The log writer in use by JDBC drivers.
- */
-public static PrintWriter
-getLogWriter()
-{
- return(log_writer);
-}
-
-/*************************************************************************/
-
-/**
- * This method sets the log writer being used by JDBC drivers. This is a
- * system-wide parameter that affects all drivers. Note that since there
- * is no way to retrieve a <code>PrintStream</code> from a
- * <code>PrintWriter</code>, this method cannot set the log stream in
- * use by JDBC. Thus any older drivers may not see this setting.
- *
- * @param log_writer The new log writer for JDBC.
- */
-public static void
-setLogWriter(PrintWriter log_writer)
-{
- DriverManager.log_writer = log_writer;
-}
-
-/*************************************************************************/
-
-/**
- * This method returns the log stream in use by JDBC.
- *
- * @return The log stream in use by JDBC.
- *
- * @deprecated Use <code>getLogWriter()</code> instead.
- */
-public static PrintStream
-getLogStream()
-{
- return(log_stream);
-}
-
-/*************************************************************************/
-
-/**
- * This method sets the log stream in use by JDBC.
- *
- * @param log_stream The log stream in use by JDBC.
- *
- * @deprecated Use <code>setLogWriter</code> instead.
- */
-public static void
-setLogStream(PrintStream log_stream)
-{
- DriverManager.log_stream = log_stream;
-}
-
-/*************************************************************************/
-
-/**
- * This method prints the specified line to the log stream.
- *
- * @param str The string to write to the log stream.
- */
-public static void
-println(String str)
-{
- if (log_stream != null) // Watch for user not using logging
- log_stream.println(str);
-}
-
-/*************************************************************************/
-
-/**
- * This method registers a new driver with the manager. This is normally
- * called by the driver itself in a static initializer.
- *
- * @param driver The new <code>Driver</code> to add.
- *
- * @exception SQLException If an error occurs.
- */
-public static void
-registerDriver(Driver driver) throws SQLException
-{
- if (!drivers.contains(driver))
- drivers.addElement(driver);
-}
-
-/*************************************************************************/
-
-/**
- * This method de-registers a driver from the manager.
- *
- * @param driver The <code>Driver</code> to unregister.
- *
- * @exception SQLException If an error occurs.
- */
-public static void
-deregisterDriver(Driver driver) throws SQLException
-{
- if (drivers.contains(driver))
- drivers.removeElement(driver);
-}
-
-/*************************************************************************/
-
-/**
- * This method returns a list of all the currently registered JDBC drivers
- * that were loaded by the current <code>ClassLoader</code>.
- *
- * @return An <code>Enumeration</code> of all currently loaded JDBC drivers.
- */
-public static Enumeration
-getDrivers()
-{
- Vector v = new Vector();
- Enumeration e = drivers.elements();
-
- // Is this right?
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
-
- while(e.hasMoreElements())
- {
- Object obj = e.nextElement();
-
- ClassLoader loader = obj.getClass().getClassLoader();
-
- if (loader == null)
- loader = ClassLoader.getSystemClassLoader();
- if (!loader.equals(cl))
- continue;
-
- v.addElement(obj);
- }
-
- return(v.elements());
-}
-
-/*************************************************************************/
-
-/**
- * This method returns a driver that can connect to the specified
- * JDBC URL string. This will be selected from among drivers loaded
- * at initialization time and those drivers manually loaded by the
- * same class loader as the caller.
- *
- * @param url The JDBC URL string to find a driver for.
- *
- * @return A <code>Driver</code> that can connect to the specified
- * URL, or <code>null</code> if a suitable driver cannot be found.
- *
- * @exception SQLException If an error occurs.
- */
-public static Driver
-getDriver(String url) throws SQLException
-{
- // FIXME: Limit driver search to the appropriate subset of loaded drivers.
-
- Enumeration e = drivers.elements();
- while(e.hasMoreElements())
- {
- Driver d = (Driver)e.nextElement();
- if (d.acceptsURL(url))
- return(d);
- }
-
- return(null);
-}
-
-/*************************************************************************/
+ /**
+ * This method sets the log writer being used by JDBC drivers. This is a
+ * system-wide parameter that affects all drivers. Note that since there
+ * is no way to retrieve a <code>PrintStream</code> from a
+ * <code>PrintWriter</code>, this method cannot set the log stream in
+ * use by JDBC. Thus any older drivers may not see this setting.
+ *
+ * @param out The new log writer for JDBC.
+ */
+ public static void setLogWriter(PrintWriter out)
+ {
+ DriverManager.log_writer = out;
+ }
/**
* This method attempts to return a connection to the specified
- * JDBC URL string.
- *
- * @param url The JDBC URL string to connect to.
- *
- * @return A <code>Connection</code> to that URL.
- *
- * @exception SQLException If an error occurs.
- */
-public static Connection
-getConnection(String url) throws SQLException
-{
- return(getConnection(url, new Properties()));
-}
-
-/*************************************************************************/
-
-/**
- * This method attempts to return a connection to the specified
- * JDBC URL string using the specified username and password.
+ * JDBC URL string using the specified connection properties.
*
* @param url The JDBC URL string to connect to.
- * @param user The username to connect with.
- * @param password The password to connect with.
+ * @param properties The connection properties.
*
* @return A <code>Connection</code> to that URL.
*
* @exception SQLException If an error occurs.
*/
-public static Connection
-getConnection(String url, String user, String password) throws SQLException
-{
- Properties p = new Properties();
-
- if (user != null)
- p.setProperty("user", user);
- if (password != null)
- p.setProperty("password", password);
-
- return(getConnection(url, p));
-}
-
-/*************************************************************************/
+ public static Connection getConnection(String url, Properties properties)
+ throws SQLException
+ {
+ Driver d = getDriver(url);
+ if (d == null)
+ throw new SQLException("Driver not found for URL: " + url);
+
+ return d.connect(url, properties);
+ }
+
+
+ /**
+ * This method attempts to return a connection to the specified
+ * JDBC URL string using the specified username and password.
+ *
+ * @param url The JDBC URL string to connect to.
+ * @param user The username to connect with.
+ * @param password The password to connect with.
+ * @return A <code>Connection</code> to that URL.
+ * @exception SQLException If an error occurs.
+ */
+ public static Connection getConnection(String url, String user,
+ String password) throws SQLException
+ {
+ Properties p = new Properties();
+
+ if (user != null)
+ p.setProperty("user", user);
+ if (password != null)
+ p.setProperty("password", password);
+
+ return getConnection(url, p);
+ }
+
+ /**
+ * This method attempts to return a connection to the specified
+ * JDBC URL string.
+ *
+ * @param url The JDBC URL string to connect to.
+ *
+ * @return A <code>Connection</code> to that URL.
+ *
+ * @exception SQLException If an error occurs.
+ */
+ public static Connection getConnection(String url) throws SQLException
+ {
+ return getConnection(url, new Properties());
+ }
+
+ /**
+ * This method returns a driver that can connect to the specified
+ * JDBC URL string. This will be selected from among drivers loaded
+ * at initialization time and those drivers manually loaded by the
+ * same class loader as the caller.
+ *
+ * @param url The JDBC URL string to find a driver for.
+ *
+ * @return A <code>Driver</code> that can connect to the specified
+ * URL, or <code>null</code> if a suitable driver cannot be found.
+ *
+ * @exception SQLException If an error occurs.
+ */
+ public static Driver getDriver(String url) throws SQLException
+ {
+ // FIXME: Limit driver search to the appropriate subset of loaded drivers.
+ Enumeration e = drivers.elements();
+ while(e.hasMoreElements())
+ {
+ Driver d = (Driver)e.nextElement();
+ if (d.acceptsURL(url))
+ return d;
+ }
+
+ return null;
+ }
+
+ /**
+ * This method registers a new driver with the manager. This is normally
+ * called by the driver itself in a static initializer.
+ *
+ * @param driver The new <code>Driver</code> to add.
+ *
+ * @exception SQLException If an error occurs.
+ */
+ public static void registerDriver(Driver driver) throws SQLException
+ {
+ if (! drivers.contains(driver))
+ drivers.addElement(driver);
+ }
/**
- * This method attempts to return a connection to the specified
- * JDBC URL string using the specified connection properties.
- *
- * @param url The JDBC URL string to connect to.
- * @param properties The connection properties.
+ * This method de-registers a driver from the manager.
*
- * @return A <code>Connection</code> to that URL.
+ * @param driver The <code>Driver</code> to unregister.
*
* @exception SQLException If an error occurs.
*/
-public static Connection
-getConnection(String url, Properties properties) throws SQLException
-{
- Driver d = getDriver(url);
- if (d == null)
- throw new SQLException("Driver not found for URL: " + url);
-
- return(d.connect(url, properties));
+ public static void deregisterDriver(Driver driver) throws SQLException
+ {
+ if (drivers.contains(driver))
+ drivers.removeElement(driver);
+ }
+
+ /**
+ * This method returns a list of all the currently registered JDBC drivers
+ * that were loaded by the current <code>ClassLoader</code>.
+ *
+ * @return An <code>Enumeration</code> of all currently loaded JDBC drivers.
+ */
+ public static Enumeration getDrivers()
+ {
+ Vector v = new Vector();
+ Enumeration e = drivers.elements();
+
+ // Is this right?
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+
+ while(e.hasMoreElements())
+ {
+ Object obj = e.nextElement();
+
+ ClassLoader loader = obj.getClass().getClassLoader();
+
+ if (loader == null)
+ loader = ClassLoader.getSystemClassLoader();
+ if (! loader.equals(cl))
+ continue;
+
+ v.addElement(obj);
+ }
+
+ return v.elements();
+ }
+
+ /**
+ * This method set the login timeout used by JDBC drivers. This is a
+ * system-wide parameter that applies to all drivers.
+ *
+ * @param login_timeout The new login timeout value.
+ */
+ public static void setLoginTimeout(int seconds)
+ {
+ DriverManager.login_timeout = login_timeout;
+ }
+
+ /**
+ * This method returns the login timeout in use by JDBC drivers systemwide.
+ *
+ * @return The login timeout.
+ */
+ public static int getLoginTimeout()
+ {
+ return login_timeout;
+ }
+
+ /**
+ * This method sets the log stream in use by JDBC.
+ *
+ * @param log_stream The log stream in use by JDBC.
+ *
+ * @deprecated Use <code>setLogWriter</code> instead.
+ */
+ public static void setLogStream(PrintStream out)
+ {
+ DriverManager.log_stream = log_stream;
+ }
+
+ /**
+ * This method returns the log stream in use by JDBC.
+ *
+ * @return The log stream in use by JDBC.
+ *
+ * @deprecated Use <code>getLogWriter()</code> instead.
+ */
+ public static PrintStream getLogStream()
+ {
+ return log_stream;
+ }
+
+ /**
+ * This method prints the specified line to the log stream.
+ *
+ * @param str The string to write to the log stream.
+ */
+ public static void println(String message)
+ {
+ if (log_stream != null) // Watch for user not using logging
+ log_stream.println(message);
+ }
}
-
-/*************************************************************************/
-
-/*
- * Constructors
- */
-
-// Keep bozos from trying to instantiate us.
-private
-DriverManager()
-{
- ;
-}
-
-} // class DriverManager
-