Bugs: Browse | Submit New | Admin

[#25631] Problem with getting the JDBC driver with JNDI

Date:
2009-04-23 08:24
Priority:
3
Submitted By:
Guillaume Smet (gsmet)
Assigned To:
Nobody (None)
Category:
AR-JDBC
State:
Open
Summary:
Problem with getting the JDBC driver with JNDI

Detailed description
Hi,

I'm currently trying to port Sonar (sonar.codehaus.org) to PostgreSQL and I have a small problem I can't fix by myself.

Sonar is using JNDI and is database agnostic so the driver isn't set in database.yml.

With PostgreSQL, it leads to an error in the following line in the configure_jndi method of jdbc_adapter.rb:
@config[:driver] = connection.meta_data.connection.java_class.name

connection.meta_data.connection is OK but connection.meta_data.connection.java_class raises the following exception:
wrong # of arguments(0 for 1)

Even if this problem is solved, I still think this line is wrong because connection.meta_data.connection returns
a org.postgresql.jdbc3.Jdbc3Connection object which isn't the driver class (the driver class for PostgreSQL is
org.postgresql.Driver).

Everything is fine if I configure the driver in database.yml but I'd really like to avoid that.

Shouldn't we try to call DriverManager.getDriver(connection.getMetaData().getURL()).getName() to get the real driver
name?

Any comment or help on how to fix this problem?

Thanks in advance.

-- 
Guillaume

Add A Comment: Notepad

Please login


Followup

Message
Date: 2009-04-23 18:26
Sender: Guillaume Smet

Done: http://kenai.com/jira/browse/ACTIVERECORD_JDBC-14 .

Thanks Nick.
Date: 2009-04-23 18:02
Sender: Nick Sieger

Hi, we no longer use this tracker to track bugs here. Can you
please file a copy of this bug at
http://kenai.com/jira/browse/ACTIVERECORD_JDBC ?

Thanks!
Date: 2009-04-23 13:06
Sender: Guillaume Smet

Here is a patch with what I had in mind. I tested it
successfully with:
- Derby,
- MySQL,
- PostgreSQL.
It uses methods defined in the JDBC specification so it
should work for every database.

Comments welcome.

-- 
Guillaume

Attached Files:

Name Description Download
fix_jndi_get_driver.diff Download

Changes:

Field Old Value Date By
File Added4500: fix_jndi_get_driver.diff2009-04-23 13:06gsmet