public class Driver extends Driver
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")
PGConnection
,
Driver
Modifier and Type | Field and Description |
---|---|
static String |
AWS_PROTOCOL |
static String |
POSTGRES_PROTOCOL |
DEFAULT_PORT, defaultProperties, loggerHandlerFile, registeredDriver, SHARED_TIMER
Constructor and Description |
---|
Driver() |
Modifier and Type | Method and Description |
---|---|
boolean |
acceptsURL(@NonNull String url)
Returns true if the driver thinks it can open a connection to the given URL.
|
@Nullable Connection |
connect(@Nullable String url,
@Nullable Properties info)
Try to make a database connection to the given URL.
|
static void |
deregister()
According to JDBC specification, this driver is registered against
DriverManager when
the class is loaded. |
@NonNull DriverPropertyInfo[] |
getPropertyInfo(@NonNull String url,
@NonNull Properties info)
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.
|
static @NonNull SharedTimer |
getSharedTimer() |
static boolean |
isRegistered() |
protected @NonNull Properties |
loadDefaultProperties() |
static SQLFeatureNotSupportedException |
notImplemented(Class<?> callClass,
@NonNull String functionName)
This method was added in v6.5, and simply throws an SQLException for an unimplemented method.
|
static @Nullable Properties |
parseURL(String url,
@Nullable Properties defaults)
Constructs a new DriverURL, splitting the specified URL into its component parts.
|
static void |
register()
Register the driver against DriverManager.
|
static void |
setAcceptAwsProtocolOnly(boolean awsProtocolOnly)
Set the acceptAwsProtocolOnly property for the driver, which controls whether protocols other than
jdbc:postgresql:aws:// will be accepted by the driver.
|
getDefaultProperties, getMajorVersion, getMinorVersion, getParentLogger, getVersion, jdbcCompliant
public static final String POSTGRES_PROTOCOL
public static final String AWS_PROTOCOL
public static void setAcceptAwsProtocolOnly(boolean awsProtocolOnly)
awsProtocolOnly
- enables the acceptAwsProtocolOnly mode of the driverprotected @NonNull Properties loadDefaultProperties() throws IOException
loadDefaultProperties
in class Driver
IOException
public @Nullable Connection connect(@Nullable String url, @Nullable Properties info) throws SQLException
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
-E <encoding>
argument to createdb.
Our protocol takes the forms:
jdbc:postgresql://host:port/database?param1=val1&...
connect
in interface Driver
connect
in class Driver
url
- the URL of the database to connect toinfo
- a list of arbitrary tag/value pairs as connection argumentsSQLException
- if a database access error occurs or the url is
null
Driver.connect(java.lang.String, java.util.Properties)
public boolean acceptsURL(@NonNull String url)
acceptsURL
in interface Driver
acceptsURL
in class Driver
url
- the URL of the driverDriver.acceptsURL(java.lang.String)
public @NonNull DriverPropertyInfo[] getPropertyInfo(@NonNull String url, @NonNull Properties info)
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
getPropertyInfo
in interface Driver
getPropertyInfo
in class Driver
url
- the Url of the database to connect toinfo
- a proposed list of tag/value pairs that will be sent on connect open.Driver.getPropertyInfo(java.lang.String, java.util.Properties)
public static @Nullable Properties parseURL(String url, @Nullable Properties defaults)
url
- JDBC URL to parsedefaults
- Default propertiespublic static SQLFeatureNotSupportedException notImplemented(Class<?> callClass, @NonNull String functionName)
callClass
- the call ClassfunctionName
- the name of the unimplemented function with the type of its argumentspublic static @NonNull SharedTimer getSharedTimer()
public static void register() throws SQLException
IllegalStateException
- if the driver is already registeredSQLException
- when called, indicating that
software.aws.rds.jdbc.postgresql.Driver should be registered instead.public static void deregister() throws SQLException
DriverManager
when
the class is loaded. This functionality is disabled as this driver
should never be registered - software.aws.rds.jdbc.postgresql.Driver
should be registered instead. Attempting to deregister this driver
will result in a SQLException.IllegalStateException
- if the driver is not registeredSQLException
- when called, indicating that this driver should never
have been registered as software.aws.rds.jdbc.postgresql.Driver
should be used instead of this driver.public static boolean isRegistered()
true
if the driver is registered against DriverManager
Copyright © 1997-2021 PostgreSQL Global Development Group. All Rights Reserved.