Ruby-plsql gem ported to JRuby

Hi all

Wanted to announce that I have ported ruby-plsql gem to JRuby and Oracle
JDBC driver.
ruby-plsql gem provides simple Ruby API for accessing Oracle PL/SQL
stored
procedures.
To learn more about the gem please visit
http://blog.rayapps.com/2008/06/26/ruby-plsql-gem-now-supports-jruby-and-oracle-jdbc-driver/
or see the source code at GitHub - rsim/ruby-plsql: ruby-plsql gem provides simple Ruby API for calling Oracle PL/SQL procedures. It could be used both for accessing Oracle PL/SQL API procedures in legacy applications as well as it could be used to create PL/SQL unit tests using Ruby testing libraries.

You can use it also as more advanced example how to use JDBC from JRuby
to
construct dynamic SQL queries and stored procedure executions.

I have also one question about how to correctly use addtional jar files
from JRuby. In my case I need to use ojdbc14.jar file which contains
Oracle
JDBC driver.
Initially I required it from original location and reqister it as JDBC
driver:

require “/usr/local/oracle/instantclient_10_2/ojdbc14.jar”
import java.sql.Statement
import java.sql.Connection
import java.sql.SQLException
import java.sql.Types
import java.sql.DriverManager
DriverManager.registerDriver Java::oracle.jdbc.driver.OracleDriver.new

and so far it worked OK.
But when I tried to get connection to Oracle:

DriverManager.getConnection
(“jdbc:oracle:thin:@ubuntu710:1521:XE”,“hr”,“hr”)

then I got error message:
NativeException: java.sql.SQLException: No suitable driver

The workaround solution that I found is to copy ojdbc14.jar to
$JRUBY_HOME/lib directory and then everything works fine.

Is there another way how to correctly load JDBC driver from external jar
file which is located in some non-standard directory?

Kind regards,
Raimonds

Hi Raimonds,

On Fri, Jun 27, 2008 at 9:06 AM, Raimonds Simanovskis
[email protected] wrote:

import java.sql.Types

The workaround solution that I found is to copy ojdbc14.jar to
$JRUBY_HOME/lib directory and then everything works fine.

Is there another way how to correctly load JDBC driver from external jar
file which is located in some non-standard directory?

Yes, the JDBC’s DriverManager double-checks the classloader of the
registered
drivers and only allows to use the dirver if the caller’s and the
driver’s classloaders are are the same.

In practical terms, it seems that the solution is to set the current
thread’s classloader to JRuby classloader. See the following for more
details:

Thanks,
–Vladimir


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Thanks Vladimir

Adding

require “jruby”
java.lang.Thread.currentThread.setContextClassLoader
(JRuby.runtime.jruby_class_loader)

solved the issue and now ojdbc14.jar can be located in any place.

Raimonds

“Vladimir S.” [email protected] wrote on 27.06.2008 10:41:10:

Hi Raimonds,

On Fri, Jun 27, 2008 at 9:06 AM, Raimonds Simanovskis
[email protected] wrote:

I have also one question about how to correctly use addtional jar files
from
JRuby. In my case I need to use ojdbc14.jar file which contains Oracle
JDBC
DriverManager.registerDriver Java::oracle.jdbc.driver.OracleDriver.new

and so far it worked OK.
But when I tried to get connection to Oracle:

DriverManager.getConnection
(“jdbc:oracle:thin:@ubuntu710:1521:XE”,“hr”,“hr”)

then I got error message:
NativeException: java.sql.SQLException: No suitable driver

The workaround solution that I found is to copy ojdbc14.jar to
$JRUBY_HOME/lib directory and then everything works fine.

Is there another way how to correctly load JDBC driver from external
jar
file which is located in some non-standard directory?

Yes, the JDBC’s DriverManager double-checks the classloader of the
registered