Jndi connection

Hello.
Here is my database.yml:

production:
adapter: jdbc
jndi: java:comp/env/mydb
driver: postgresql
encoding: unicode
wait_timeout: 5
pool: 5

and here is my tomcat configuration:

I deploy the war under tomcat but I’ve this error:

org.jruby.rack.RackInitializationException: jdbc adapter requires
driver class and url

What I’ve missed?
Thank you.

Mauro -

I’m not certain, but I access Postgres through JDBC, and I have this in
my database.yml:

adapter: jdbcpostgresql

and have the following in my Gemfile:

gem ‘activerecord-jdbc-adapter’
gem ‘jdbc-postgres’

  • Keith

Keith R. Bennett
http://about.me/keithrbennett

On 27 December 2012 09:48, Keith B. [email protected]
wrote:

Mauro -

I’m not certain, but I access Postgres through JDBC, and I have this in my
database.yml:

adapter: jdbcpostgresql

…and have the following in my Gemfile:

gem ‘activerecord-jdbc-adapter’
gem ‘jdbc-postgres’

Do you use a jndi connection?

This works for running our application under Tomcat with a Postgres
database:

production:
adapter: jdbc
jndi: java:comp/env/jdbc/cxo
pool: 99999

I suspect your failure comes from specifying “driver”. The Ruby
connection code does not need to know the underlying driver. Tomcat
takes care of that. Notice that your error message is coming from the
Ruby, not from Tomcat.

Also, here is my commit message for setting “pool” very large:
The activerecord-jdbc-adapter does not pool JNDI database
connections.
This is a good thing. The JNDI database connection provider
(Tomcat)
is handling connection pooling. What activerecord-jdbc-adapter does
not do is prevent activerecord from imposing its own limit on
database
connections. We depend on Tomcat to enforce the connection limit.
So, we tell activerecord to allow essentially an infinite number of
database connections.

Oops, no, sorry, I don’t. Never mind :wink:

  • Keith

Keith R. Bennett
http://about.me/keithrbennett

On 27 December 2012 11:32, Mauro [email protected] wrote:

code does not need to know the underlying driver. Tomcat takes care of that.
Notice that your error message is coming from the Ruby, not from Tomcat.

I’ve found instructions here: https://gist.github.com/1560215 and is
specified driver: postgresql in database.yml configuration.
However now I try without driver parameter.

Ok, without the driver parameter it works, thank you very much.
I think https://gist.github.com/1560215 must be updated.

On 27 December 2012 11:08, Bruce A. [email protected] wrote:

Notice that your error message is coming from the Ruby, not from Tomcat.
I’ve found instructions here: https://gist.github.com/1560215 and is
specified driver: postgresql in database.yml configuration.
However now I try without driver parameter.

Sorry it was a false alarm.
The error still exists:
My database.yml:

production:
adapter: jdbc
jndi: java:comp/env/jdbc/my_db
encoding: unicode
wait_timeout: 5
pool: 99999

The error:

org.jruby.rack.RackInitializationException: jdbc adapter requires
driver class and url

tomcat context.xml

What I’ve missed again?

On 27 December 2012 17:21, Krum B. [email protected] wrote:

Next, you have the ActiveRecord-JDBC adapter. I see that you have specified
“adapter: jdbc” although you are using a PostgreSQL server behind - maybe
you have some good reasons for doing that ?

I’ve found a how to here, https://gist.github.com/1560215.
As you can see the adapter parameter in database.yml is jdbc.

Just some idea: If I were you, I would first ensure that the JDBC
DataSource is successfully created by Tomcat, and successfully exposed
in
its JDNI space (in other words, ensure that what you want to consume is
existing and available - in the Java domain - as a first step; and as a
second step - try to see whether the JRuby client is able to find it). I
would open some JConsole session, or use other means of establishing JMX
connection with the Tomcat, and then browse over Catalina’s MBeans to
see
whether the DataSource exists. Another possible way to check this, of
course, is to make some simple Proof-Of-Concept Java consumption from
inside a small web application that the DS is available (lookup should
be
sufficient). Why am I saying all this ? Mainly because Tomcat’s
proprietary
way of configuration data sources has always been not-that-friendly to
me,
and I used to have similar problems - not getting the exact
configuration.
Have you checked this ? It will help you to find out where is the
problem -
in Tomcat’s configuration, or at the client side - in AR-JDBC adapter.

Next, you have the ActiveRecord-JDBC adapter. I see that you have
specified
“adapter: jdbc” although you are using a PostgreSQL server behind -
maybe
you have some good reasons for doing that ?

Cheers,
Krum.

I agree with Krum. I’d imagine that even if Java handles the data base
connections, the Active Record code needs to know about the underlying
data base implementation, for example so that it can generate the
correct SQL for that DB. Maybe you could try the jdbcpostgresql adapter
from the jdbc-postgres gem, as I described in my previous message, and
see if that works?:

adapter: jdbcpostgresql

and have the following in my Gemfile:

gem ‘activerecord-jdbc-adapter’
gem ‘jdbc-postgres’

  • Keith

Keith R. Bennett
http://about.me/keithrbennett

So when you specify the driver: postgres in your database.yml, and
include the following in your Gemfile:

gem ‘activerecord-jdbcpostgresql-adapter’
gem ‘jruby-openssl’

you still get the same error?

If you’ve done the former (database.yml), but not the latter, I wonder
if that could explain the absence of a class name to correspond to the
driver name.

  • Keith

I agree with Krum. I’d imagine that even if Java handles the data base
connections, the Active Record code needs to know about the underlying
data base implementation, for example so that it can generate the
correct SQL for that DB. Maybe you could try the jdbcpostgresql adapter
from the jdbc-postgres gem, as I described in my previous message, and
see if that works?:

adapter: jdbcpostgresql

and have the following in my Gemfile:

gem ‘activerecord-jdbc-adapter’
gem ‘jdbc-postgres’

  • Keith

Keith R. Bennett
http://about.me/keithrbennett

Now:

production:
adapter: jdbcpostgresql
jndi: java:comp/env/jdbc/albofornitori
driver: postgresql
encoding: unicode
wait_timeout: 5
pool: 5

error:

org.jruby.rack.RackInitializationException: The driver encountered an
unknown error: Cannot create JDBC driver of class
‘org.postgresql.Driver’ for connect URL
‘jdbc:postgresql://svsopsql01.xxx:5432/albo_fornitori’

On 27 December 2012 18:19, Mauro [email protected] wrote:

error:

org.jruby.rack.RackInitializationException: The driver encountered an
unknown error: Cannot create JDBC driver of class
‘org.postgresql.Driver’ for connect URL
‘jdbc:postgresql://svsopsql01.xxx:5432/albo_fornitori’

I’ve the gems in my Gemfile.

I researched this a little, and found that this error could occur if the
JDBC driver jar file is not available/found, but the JDBC Postgres gem
contains it, so it doesn’t seem to be that.

I do think we’re making progress, though, and checking that URL with
another client is a great idea.

  • Keith

Keith R. Bennett
http://about.me/keithrbennett

OK, so we’ve reached the JDBC URL. Could you now test this URL via some
client - be it some GUI for SQL interaction with the data base, or a
standalone Java client program, or whatever ? Maybe you miss some port,
or
other tricky detail for that URL. What does a fast Googling about
similar
issues with the Postgre arjdbc adapter show ? Or with JDBC access to
Postgre in general - maybe you use an old version of the JDBC driver.
And, just for completeness, did you check that the DS is there in JNDI ?

On 27 December 2012 19:05, Keith B. [email protected]
wrote:

I researched this a little, and found that this error could occur if the
JDBC driver jar file is not available/found, but the JDBC Postgres gem
contains it, so it doesn’t seem to be that.

I do think we’re making progress, though, and checking that URL with another
client is a great idea.

After trying more times I think I’ve found the problem.
It’s my fault.
Under tomcat I’ve more than one application, each using it’s own
database.
So I put all jndi definitions under context.xml that is loaded for
each web application.
That is wrong, every application must have it’s own context definition.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs