Postgresql database driver java

Postgresql database driver java

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»)

Constructor Summary

Method Summary

According to JDBC specification, this driver is registered against DriverManager when the class is loaded.

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.

Methods inherited from class java.lang.Object

Constructor Detail

Driver

Method Detail

connect

public @Nullable Connection connect(String url, @Nullable Properties info) throws SQLException
  • 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.
Читайте также:  Php files gets downloaded

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 argument to createdb.

Our protocol takes the forms:

jdbc:postgresql://host:port/database?param1=val1&.

acceptsURL

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:

getPropertyInfo

public 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. 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

getMajorVersion

public int getMajorVersion()

getMinorVersion

public int getMinorVersion()

getVersion

@Deprecated public static String getVersion()

jdbcCompliant

public boolean jdbcCompliant()

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).

parseURL

public static @Nullable Properties parseURL(String url, @Nullable Properties defaults)

notImplemented

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 strace

getParentLogger

getSharedTimer

register

Register the driver against DriverManager . This is done automatically when the class is loaded. Dropping the driver from DriverManager’s list is possible using deregister() method.

Читайте также:  Run python code on windows

deregister

According to JDBC specification, this driver is registered against 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.

isRegistered

public static boolean isRegistered()

Источник

Download

Binary JAR file downloads of the JDBC driver are available here and the current version with Maven Repository. Because Java is platform neutral, it is a simple process of just downloading the appropriate JAR file and dropping it into your classpath. Source versions are also available here for recent driver versions. Latest SNAPSHOT versions.

Latest Versions

This is the current version of the driver. Unless you have unusual requirements (running old applications or JVMs), this is the driver you should be using. It supports PostgreSQL 8.2 or newer and requires Java 6 or newer. It contains support for SSL and the javax.sql package.

If you are using Java 8 or newer then you should use the JDBC 4.2 version.

If you are using Java 7 then you should use the JDBC 4.1 version.

If you are using Java 6 then you should use the JDBC 4.0 version.

Older Versions

Many other versions of the JDBC driver are available. This includes development versions, compatibility with older JDKs, and previous versions of the driver.

  • Getting Started
  • Initializing the Driver
  • Using SSL
  • Issuing a Query and Processing the Result
  • Calling Stored Functions and Procedures
  • Storing Binary Data
  • JDBC escapes
  • PostgreSQL™ Extensions to the JDBC API
  • Using the Driver in a Multithreaded or a Servlet Environment
  • Connection Pools and Data Sources
  • Logging using java.util.logging
  • Further Reading
Читайте также:  Setting Font Size

Источник

Оцените статью