On Sat, May 16, 2009 at 11:08 PM, Paul F. [email protected]
wrote:
Could this still a problem related to
$LOAD_PATH.unshift File.dirname(FILE)
connection_str = “jdbc:h2:db1;USER=sa”
begin
db = Sequel.connect(connection_str)
db.test_connection
puts “Open Database OK”
rescue
puts “Open Database Failed = #{connection_str}”
nil
end
We have to jump through some hoops with AR-JDBC in order to use jar
files require’d by JRuby – perhaps you’re running into this issue.
The issue is the following:
http://java.sun.com/j2se/1.5.0/docs/api/java/sql/DriverManager.html
“When the method getConnection is called, the DriverManager will
attempt to locate a suitable driver from amongst those loaded at
initialization and those loaded explicitly using the same classloader
as the current applet or application.”
The problem is that any drivers require’d by JRuby end up in a child
classloader of the one that started JRuby, so DriverManager doesn’t
see them. The workaround (which may require patching Sequel) is to do
something like the following 1:
def connection(url, user, pass)
Jdbc::DriverManager.getConnection(url, user, pass)
rescue
# bypass DriverManager to get around problem with dynamically
loaded jdbc drivers
props = java.util.Properties.new
props.setProperty(“user”, user)
props.setProperty(“password”, pass)
create.connect(url, props)
end
def create
driver_class.new
end
/Nick
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email