|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.postgresql.Driver
public class 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
Field Summary | |
---|---|
static int |
DEBUG
|
static int |
INFO
|
static int |
MAJORVERSION
|
static int |
MINORVERSION
|
static int |
OFF
|
Constructor Summary | |
---|---|
Driver()
|
Method Summary | |
---|---|
boolean |
acceptsURL(String url)
Returns true if the driver thinks it can open a connection to the given URL. |
Connection |
connect(String url,
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. |
static int |
getLogLevel()
|
int |
getMajorVersion()
Gets the drivers major version number |
int |
getMinorVersion()
Get the drivers minor version number |
Logger |
getParentLogger()
|
DriverPropertyInfo[] |
getPropertyInfo(String url,
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 SharedTimer |
getSharedTimer()
|
static String |
getVersion()
Returns the server version series of this driver and the specific build number. |
static boolean |
isRegistered()
|
boolean |
jdbcCompliant()
Report whether the driver is a genuine JDBC compliant driver. |
static SQLFeatureNotSupportedException |
notImplemented(Class<?> callClass,
String functionName)
This method was added in v6.5, and simply throws an SQLException for an unimplemented method. |
static Properties |
parseURL(String url,
Properties defaults)
Constructs a new DriverURL, splitting the specified URL into its component parts |
static void |
register()
Register the driver against DriverManager . |
static void |
setLogLevel(int logLevel)
used to turn logging on to a certain level, can be called by specifying fully qualified class ie org.postgresql.Driver.setLogLevel() |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEBUG
public static final int INFO
public static final int OFF
public static final int MAJORVERSION
public static final int MINORVERSION
Constructor Detail |
---|
public Driver()
Method Detail |
---|
public Connection connect(String url, Properties info) throws SQLException
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. user - (required) The user to connect as password - (optional) The password for the user ssl - (optional) Use SSL when connecting to the server readOnly - (optional) Set connection to read-only by default charSet - (optional) The character set to be used for converting to/from the database to unicode. If multibyte is enabled on the server then the character set of the database is used as the default, otherwise the jvm character encoding is used as the default. This value is only used when connecting to a 7.2 or older server. loglevel - (optional) Enable logging of messages from the driver. The value is an integer from 0 to 2 where: OFF = 0, INFO = 1, DEBUG = 2 The output is sent to DriverManager.getPrintWriter() if set, otherwise it is sent to System.out. compatible - (optional) This is used to toggle between different functionality as it changes across different releases of the jdbc driver code. The values here are versions of the jdbc client and not server versions. For example in 7.1 get/setBytes worked on LargeObject values, in 7.2 these methods were changed to work on bytea values. This change in functionality could be disabled by setting the compatible level to be "7.1", in which case the driver will revert to the 7.1 functionality.
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
url
- the URL of the database to connect toinfo
- a list of arbitrary tag/value pairs as connection arguments
SQLException
- if a database access error occursDriver.connect(java.lang.String, java.util.Properties)
public boolean acceptsURL(String url)
acceptsURL
in interface Driver
url
- the URL of the driver
Driver.acceptsURL(java.lang.String)
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
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
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 int getMajorVersion()
getMajorVersion
in interface Driver
public int getMinorVersion()
getMinorVersion
in interface Driver
public static String getVersion()
public boolean jdbcCompliant()
For PostgreSQL, this is not yet possible, as we are not SQL92 compliant (yet).
jdbcCompliant
in interface Driver
public static Properties parseURL(String url, Properties defaults)
url
- JDBC URL to parsedefaults
- Default properties
public static SQLFeatureNotSupportedException notImplemented(Class<?> callClass, String functionName)
callClass
- the call ClassfunctionName
- the name of the unimplemented function with the type of its arguments
public static void setLogLevel(int logLevel)
logLevel
- sets the level which logging will respond to OFF turn off logging INFO being
almost no messages DEBUG most verbosepublic static int getLogLevel()
public Logger getParentLogger() throws SQLFeatureNotSupportedException
SQLFeatureNotSupportedException
public static SharedTimer getSharedTimer()
public static void register() throws SQLException
DriverManager
. This is done automatically when the class is
loaded. Dropping the driver from DriverManager's list is possible using deregister()
method.
IllegalStateException
- if the driver is already registered
SQLException
- if registering the driver failspublic static void deregister() throws SQLException
DriverManager
when
the class is loaded. To avoid leaks, this method allow unregistering the driver so that the
class can be gc'ed if necessary.
IllegalStateException
- if the driver is not registered
SQLException
- if deregistering the driver failspublic static boolean isRegistered()
true
if the driver is registered against DriverManager
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |