The Java SQL framework allows for multiple database drivers. Each driver should supply a class that implements the Driver interface
The DriverManager will try to load as many drivers as it can find and then for any given connection request, it will ask each driver in turn to try to connect to the target URL.
It is strongly recommended that each Driver class should be small and standalone so that the Driver class can be loaded and queried without bringing in vast quantities of supporting code.
When a Driver class is loaded, it should create an instance of itself and register it with the DriverManager. This means that a user can load and register a driver by doing Class.forName("foo.bah.Driver")
org.postgresql.PGConnection , java.sql.Driver
| Modifier and Type | Class and Description |
|---|---|
| private static class | Driver.
Perform a connect in a separate thread; supports getting the results from the original thread while enforcing a login timeout. |
| Modifier and Type | Field and Description |
|---|---|
| private @Nullable Properties | |
| private final ResourceLock | |
| private static final Logger | |
| private static final Logger | |
| private static @Nullable Driver | |
| private static final SharedTimer |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | Returns: true if this driver accepts the given URLthe URL of the driver url)Implements java. Returns true if the driver thinks it can open a connection to the given URL. |
| public @Nullable Connection | Returns: a connection to the URL or null if it isnt usthe URL of the database to connect to url, @Nullable Properties a list of arbitrary tag/value pairs as connection arguments info)Implements java. Try to make a database connection to the given URL. |
| public static void | deregister()
According to JDBC specification, this driver is registered against |
| private static <T> T | |
| private Properties | |
| public int | getMajorVersion()
Implements java. Retrieves the driver's major version number. |
| public int | getMinorVersion()
Implements java. Gets the driver's minor version number. |
| public Logger | getParentLogger()
Implements java. Return the parent Logger of all the Loggers used by this driver. |
| public DriverPropertyInfo[] | Returns: An array of DriverPropertyInfo objects describing possible properties. This array may be an empty array if no properties are requiredthe Url of the database to connect to url, Properties a proposed list of tag/value pairs that will be sent on connect open. info)Implements java. The getPropertyInfo method is intended to allow a generic GUI tool to discover what properties it should prompt a human for in order to get enough information to connect to a database. |
| public static SharedTimer | |
| public static String | Returns: JDBC driver version
Deprecated
use
getMajorVersion() and getMinorVersion() instead
Returns the server version series of this driver and the specific build number. |
| private static HostSpec[] | |
| public static boolean | |
| public boolean | jdbcCompliant()
Implements java. Report whether the driver is a genuine JDBC compliant driver. |
| private Properties | |
| private static Connection | Returns: a new connectionthe original URL url, Properties the parsed/defaulted connection properties props)Create a connection from URL and properties. |
| public static SQLFeatureNotSupportedException | Returns: PSQLException with a localized message giving the complete description of the unimplemented functionthe call Class callClass, String the name of the unimplemented function with the type of its arguments functionName)This method was added in v6.5, and simply throws an SQLException for an unimplemented method. |
| public static @Nullable Properties | Returns: Properties with elements added from the urlJDBC URL to parse url, @Nullable Properties Default properties defaults)Constructs a new DriverURL, splitting the specified URL into its component parts. |
| public static void | |
| private void | setupLoggerFromProperties(final Properties
Connection Properties props)this is an empty method left here for graalvm we removed the ability to setup the logger from properties due to a security issue |
| private static long | |
| private static @Nullable String |
| defaultProperties | back to summary |
|---|---|
| private @Nullable Properties defaultProperties | |
| lock | back to summary |
|---|---|
| private final ResourceLock lock | |
| LOGGER | back to summary |
|---|---|
| private static final Logger LOGGER | |
| PARENT_LOGGER | back to summary |
|---|---|
| private static final Logger PARENT_LOGGER | |
| registeredDriver | back to summary |
|---|---|
| private static @Nullable Driver registeredDriver | |
| SHARED_TIMER | back to summary |
|---|---|
| private static final SharedTimer SHARED_TIMER | |
| Driver | back to summary |
|---|---|
| public Driver() | |
| acceptsURL | back to summary |
|---|---|
| public boolean acceptsURL(String url) Implements java. Returns true if the driver thinks it can open a connection to the given URL. Typically, drivers will return true if they understand the subprotocol specified in the URL and false if they don't. Our protocols start with jdbc:postgresql:
| |
| connect | back to summary |
|---|---|
| public @Nullable Connection connect(String url, @Nullable Properties info) throws SQLException Implements java. Try to make a database connection to the given URL. The driver should return "null" if it realizes it is the wrong kind of driver to connect to the given URL. This will be common, as when the JDBC driverManager is asked to connect to a given URL, it passes the URL to each loaded driver in turn. The driver should raise an SQLException if it is the right driver to connect to the given URL, but has trouble connecting to the database. The java.util.Properties argument can be used to pass arbitrary string tag/value pairs as connection arguments.
Normally, at least "user" and "password" properties should be included in the properties. For a
list of supported character encoding , see
http://java.sun.com/products/jdk/1.2/docs/guide/internat/encoding.doc.html Note that you will
probably want to have set up the Postgres database itself to use the same encoding, with the
Our protocol takes the forms: jdbc:postgresql://host:port/database?param1=val1&...
| |
| deregister | back to summary |
|---|---|
| public static void deregister() throws SQLException According to JDBC specification, this driver is registered against
| |
| doPrivileged | back to summary |
|---|---|
| private static <T> T doPrivileged(PrivilegedExceptionAction<T> action) throws Throwable | |
| getDefaultProperties | back to summary |
|---|---|
| private Properties getDefaultProperties() throws IOException | |
| getMajorVersion | back to summary |
|---|---|
| public int getMajorVersion() Implements java. Doc from java. Retrieves the driver's major version number. Initially this should be 1.
| |
| getMinorVersion | back to summary |
|---|---|
| public int getMinorVersion() Implements java. Doc from java. Gets the driver's minor version number. Initially this should be 0.
| |
| getParentLogger | back to summary |
|---|---|
| public Logger getParentLogger() Implements java. Doc from java. Return the parent Logger of all the Loggers used by this driver. This should be the Logger farthest from the root Logger that is still an ancestor of all of the Loggers used by this driver. Configuring this Logger will affect all of the log messages generated by the driver. In the worst case, this may be the root Logger. | |
| getPropertyInfo | back to summary |
|---|---|
| public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) Implements java. The getPropertyInfo method is intended to allow a generic GUI tool to discover what properties it should prompt a human for in order to get enough information to connect to a database. Note that depending on the values the human has supplied so far, additional values may become necessary, so it may be necessary to iterate through several calls to getPropertyInfo
| |
| getSharedTimer | back to summary |
|---|---|
| public static SharedTimer getSharedTimer() | |
| getVersion | back to summary |
|---|---|
| public static String getVersion()
Deprecated use Returns the server version series of this driver and the specific build number.
| |
| hostSpecs | back to summary |
|---|---|
private static HostSpec[] hostSpecs(Properties props)
| |
| isRegistered | back to summary |
|---|---|
public static boolean isRegistered()
| |
| jdbcCompliant | back to summary |
|---|---|
| public boolean jdbcCompliant() Implements java. Report whether the driver is a genuine JDBC compliant driver. A driver may only report "true" here if it passes the JDBC compliance tests, otherwise it is required to return false. JDBC compliance requires full support for the JDBC API and full support for SQL 92 Entry Level. For PostgreSQL, this is not yet possible, as we are not SQL92 compliant (yet).
| |
| loadDefaultProperties | back to summary |
|---|---|
| private Properties loadDefaultProperties() throws IOException | |
| makeConnection | back to summary |
|---|---|
| private static Connection makeConnection(String url, Properties props) throws SQLException Create a connection from URL and properties. Always does the connection work in the current thread without enforcing a timeout, regardless of any timeout specified in the properties.
| |
| notImplemented | back to summary |
|---|---|
| public static SQLFeatureNotSupportedException notImplemented(Class<?> callClass, String functionName) This method was added in v6.5, and simply throws an SQLException for an unimplemented method. I decided to do it this way while implementing the JDBC2 extensions to JDBC, as it should help keep the overall driver size down. It now requires the call Class and the function name to help when the driver is used with closed software that don't report the stack trace
| |
| parseURL | back to summary |
|---|---|
| public static @Nullable Properties parseURL(String url, @Nullable Properties defaults) Constructs a new DriverURL, splitting the specified URL into its component parts.
| |
| register | back to summary |
|---|---|
| public static void register() throws SQLException Register the driver against
| |
| setupLoggerFromProperties | back to summary |
|---|---|
| private void setupLoggerFromProperties(final Properties props) this is an empty method left here for graalvm we removed the ability to setup the logger from properties due to a security issue
| |
| timeout | back to summary |
|---|---|
private static long timeout(Properties props)
| |
| urlDecode | back to summary |
|---|---|
| private static @Nullable String urlDecode(String url) | |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private final ResourceLock | |
| private final Condition | |
| private final Properties | |
| private @Nullable Connection | |
| private @Nullable Throwable | |
| private final String |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public Connection | Returns: the new connection, if successfultimeout in milliseconds timeout)Get the connection result from this (assumed running) thread. |
| public void |
| abandoned | back to summary |
|---|---|
| private boolean abandoned | |
| lock | back to summary |
|---|---|
| private final ResourceLock lock | |
| lockCondition | back to summary |
|---|---|
| private final Condition lockCondition | |
| props | back to summary |
|---|---|
| private final Properties props | |
| result | back to summary |
|---|---|
| private @Nullable Connection result | |
| resultException | back to summary |
|---|---|
| private @Nullable Throwable resultException | |
| url | back to summary |
|---|---|
| private final String url | |
| ConnectThread | back to summary |
|---|---|
| pack-priv ConnectThread(String url, Properties props) | |
| getResult | back to summary |
|---|---|
| public Connection getResult(long timeout) throws SQLException Get the connection result from this (assumed running) thread. If the timeout is reached without a result being available, a SQLException is thrown.
| |
| run | back to summary |
|---|---|
| public void run() Implements java. Doc from java. Runs this operation.
| |