From: David Wall <d.wall@computer.org>
To: pgsql-jdbc@postgresql.org
Subject: Re: DriverManager.registerDriver - registers twice?
Date: Mon, 21 Jul 2014 20:27:24 -0700
Message-ID: <53CDDA1C.3040904@computer.org> (raw)
In-Reply-To: <53CDBAD8.8000005@computer.org>
References: <53CDBAD8.8000005@computer.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>
Perhaps I've answered my own question. Looks like I really only need to
do the Class.forName() call and the driver will register itself.
That leads to the question when will the driver deregister itself? We
previously did the register and deregister ourselves, but if the driver
is registering on its own, how does it know to deregister (such as when
my webapp is stopped)?
On 7/21/2014 6:14 PM, David Wall wrote:
> I have code like the following:
>
> Class<?> driverClass = Class.forName("org.postgresql.Driver");
> driver = (java.sql.Driver)driverClass.newInstance();
> DriverManager.registerDriver(driver);
>
> When I check before this code to see what driver's are available via
> DriverManager.getDrivers(), it reports this (note there's only one
> non-PG driver for JDBC/ODBC):
>
> 18:03:14 BEFORE REGISTER DriverManager.getDrivers() returned driver:
> sun.jdbc.odbc.JdbcOdbcDriver@3315a56d name:
> *sun.jdbc.odbc.JdbcOdbcDriver*; accepts URL
> jdbc:postgresql://localhost.localdomain/demo: *false*
>
> But right after, I show the driver instance I created, then do
> DriverManager.getDrivers() again, but this time I get TWO PG JDBC
> drivers (along with the JDBC/ODBC), the second of which matches the
> one I registered.
>
> 18:03:14 DriverManager.registerDriver() org.postgresql.Driver@*3086f9bf
>
> *18:03:14 AFTER REGISTER DriverManager.getDrivers() returned driver:
> sun.jdbc.odbc.JdbcOdbcDriver@3315a56d name:
> sun.jdbc.odbc.JdbcOdbcDriver; accepts URL
> jdbc:postgresql://localhost.localdomain/demo: false
> 18:03:14 AFTER REGISTER DriverManager.getDrivers() returned driver:
> org.postgresql.Driver@*29559094 *name: org.postgresql.Driver; accepts
> URL jdbc:postgresql://localhost.localdomain/demo: *true*
> 18:03:14 AFTER REGISTER DriverManager.getDrivers() returned driver:
> org.postgresql.Driver@*3086f9bf*name: org.postgresql.Driver; accepts
> URL jdbc:postgresql://localhost.localdomain/demo: *true*
>
> Why are there two? Where does the org.postgresql.Driver@*29559094
> *instance come from?
>
> I am running Java 1.7.0_25 with PG JDBC driver
> postgresql-9.2-1003.jdbc4.jar.
>
> Thanks,
> David
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: d.wall@computer.org
Subject: Re: DriverManager.registerDriver - registers twice?
In-Reply-To: <53CDDA1C.3040904@computer.org>
References: <53CDBAD8.8000005@computer.org> <53CDDA1C.3040904@computer.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox