Thread: forName finds Driver but getConnection doesn't (AGAIN)

forName finds Driver but getConnection doesn't (AGAIN)

From
Deepak Vasudevan K P
Date:
Hi all,
  I'm in the same situation where Dennis King was on 19 Nov 2002.
  I'm trying to connect to pgsql using JDBC (on a RHL 8.0) and for me, as it was with Dennis, forName registers the Driver, but getConnection throws the exception "Driver not found".
  I use JDK 1.3.1,
  tried postgresql JDBC driver: "pg72jdbc2.jar" from http://jdbc.postgresql.org/
  running java as : $>java -cp ./pg72jdbc2.jar <myClassFile>
  The source for myClassFile has the following specs
    Class.forName("org.postgresql.Driver");
    ...
    Driver.getConnection("jdbc:postgresql:postgres","postgres"); // throws the "Driver Not Found" exception.
   <Here  'postgres' is the database name  and 'postgres' is a user>
 
  BTW I tried the same Driver in Windows (2000 prof, jdk1.4.1, forte for Java) and there getConnection worked, but the connection was refused by the RHL DB host (I've edited the pg_hba.conf file). That was just a try, I'd stick to RHL.
 
  Dennis any luck with your tries? Did you compile one of those sources?
 
  If anyone can help I would be grateful.
Deepak.


Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!

Re: forName finds Driver but getConnection doesn't (AGAIN)

From
Paul Thomas
Date:
On 18/06/2003 19:49 Deepak Vasudevan K P wrote:

>   If anyone can help I would be grateful.
> Deepak.
>

Puzzling. I wonder if there there might be some subtle incompatability
between the 1.3.1 JVM and whatever the driver was built with. Have you
tried enabling logging with DriverManager.setLogStream(...)? You can then
do a DriverManager.getDrivers() after your forName(...) to see if the
driver manager has picked it up correctly at that point. Alternatively,
have you tried building the driver yourself from the source?

A final option would be to use JDK 1.4.1 and upgrade PostgeSQL to 7.3.3
from source. I've done that on 2 RH7.3 boxes here and its really easy.
Just remember to also edit /etc/init.d/postgresql to change the version
test to 7.3 or you can't restart the db using service postgresql start :)

good luck

--
Paul Thomas
+------------------------------+---------------------------------------------+
| Thomas Micro Systems Limited | Software Solutions for the Smaller
Business |
| Computer Consultants         |
http://www.thomas-micro-systems-ltd.co.uk   |
+------------------------------+---------------------------------------------+

Re: forName finds Driver but getConnection doesn't (AGAIN)

From
Thomas Kellerer
Date:
Deepak Vasudevan K P schrieb:
> Hi all,
>   I'm in the same situation where Dennis King was on 19 Nov 2002.
>   I'm trying to connect to pgsql using JDBC (on a RHL 8.0) and for me,
> as it was with Dennis, forName registers the Driver, but getConnection
> throws the exception "Driver not found".
>   I use JDK 1.3.1,
>   tried postgresql JDBC driver: "pg72jdbc2.jar" from
> http://jdbc.postgresql.org/
>   running java as : $>java -cp ./pg72jdbc2.jar <myClassFile>
>   The source for myClassFile has the following specs
>     Class.forName("org.postgresql.Driver");
>     ...
>     Driver.getConnection("jdbc:postgresql:postgres","postgres"); //
> throws the "Driver Not Found" exception.
>    <Here  '*postgres' *is the database name  and '*postgres' *is a user>
>
>   BTW I tried the same Driver in Windows (2000 prof, jdk1.4.1, forte for
> Java) and there getConnection worked, but the connection was refused by
> the RHL DB host (I've edited the pg_hba.conf file). That was just a try,
> I'd stick to RHL.
>
So far it looks fine to me. The only thing that strikes me, is the way you
define your classpath. Did you try:

java -cp .:pg72jdbc2.jar myClass

If the .jar file is in the current directory, I don't see a reason to
qualify it with a ./ at the beginning. Including the current directory
might help as well.

Thomas


Re: forName finds Driver but getConnection doesn't (AGAIN)

From
Dave Cramer
Date:
Can you try specifying the host in the URL and see if that fixes this
problem?

I.E. change to jdbc:postgresql://localhost/postgres


Dave
On Wed, 2003-06-18 at 14:49, Deepak Vasudevan K P wrote:
> Hi all,
>   I'm in the same situation where Dennis King was on 19 Nov 2002.
>   I'm trying to connect to pgsql using JDBC (on a RHL 8.0) and for me,
> as it was with Dennis, forName registers the Driver, but getConnection
> throws the exception "Driver not found".
>   I use JDK 1.3.1,
>   tried postgresql JDBC driver: "pg72jdbc2.jar" from
> http://jdbc.postgresql.org/
>   running java as : $>java -cp ./pg72jdbc2.jar <myClassFile>
>   The source for myClassFile has the following specs
>     Class.forName("org.postgresql.Driver");
>     ...
>     Driver.getConnection("jdbc:postgresql:postgres","postgres"); //
> throws the "Driver Not Found" exception.
>    <Here  'postgres' is the database name  and 'postgres' is a user>
>
>   BTW I tried the same Driver in Windows (2000 prof, jdk1.4.1, forte
> for Java) and there getConnection worked, but the connection was
> refused by the RHL DB host (I've edited the pg_hba.conf file). That
> was just a try, I'd stick to RHL.
>
>   Dennis any luck with your tries? Did you compile one of those
> sources?
>
>   If anyone can help I would be grateful.
> Deepak.
>
>
> ______________________________________________________________________
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!
--
Dave Cramer <Dave@micro-automation.net>