Jruby 1.5 require 'sqljdbc.jar' no longer working

to load the sqljdbc.jar I’ve been using require ‘sqljdbc.jar’ with that
jar file located in the sources directory and then using java_import to
call the class name. This worked in jruby 1.4 but now does not work in
1.5 … has something changed in the way java libs are loaded?

What do you mean by the “sources” directory? If the jar is somewhere
in load path, it should be found by that require. Can you describe how
your project is laid out and give an example script?

On Thu, May 13, 2010 at 6:57 PM, Christopher Dancy
[email protected] wrote:

  http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Charles Nutter wrote:

What do you mean by the “sources” directory? If the jar is somewhere
in load path, it should be found by that require. Can you describe how
your project is laid out and give an example script?

On Thu, May 13, 2010 at 6:57 PM, Christopher Dancy
[email protected] wrote:

  http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

I apologize for not being clear … I have the sqljdbc.jar in the same
directory as the ruby files I’m executing. I’ve not changed the ruby
files at all I’ve only changed the fact that I’m executing with jruby
1.5. Here is a snippet of code that craps out …

require ‘rubygems’
require ‘java’
require ‘property’
require ‘sqljdbc.jar’

module DatabaseHelper

include Java
include_package ‘java.lang’
include_package ‘java.sql’

java_import(“com.microsoft.sqlserver.jdbc.SQLServerDriver”)

   conn = 

JavaSql::DriverManager.getConnection("jdbc:sqlserver://:;databaseName=

When running the above code I get this exception thrown:

RuntimeError: java.sql.SQLException: No suitable driver found for
jdbc:sqlserver://:;databaseName=

This code works perfectly fine under jruby 1.4 but craps out under jruby
1.5. Just wondering if something changed in the way of loading java
libs?

Vladimir S. wrote:

Hi Christopher,

Could you try to run your script with -Xnobootclasspath option.

jruby -Xnobootclasspath …

Any difference? I assume you’re on Windows, right?

Thanks,
–Vladimir

On Fri, May 14, 2010 at 2:53 PM, Christopher Dancy
[email protected] wrote:

�include_package ‘java.sql’
jdbc:sqlserver://:;databaseName=

� �http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hey Vladimir,

 Tried with -Xnobootclasspath option and still the same Exception is 

thrown.

Hi Christopher,

I bisect the problem to the following commit:

commit 61a000f7d152ce79c90a03ea33ab3e357aaca9bc
Date: Sun Apr 11 15:54:21 2010 -0500
When loading classes for JI, don’t force them to initialize right away
(needed for compilers, etc, where class will never actually be
executed).

So, basically, doing java_import does not initialize the class
anymore, hence JDBC can’t find the driver.

As a workaround, I could recommend the following:
require ‘jruby’
java.lang.Class.for_name(“com.microsoft.sqlserver.jdbc.SQLServerDriver”,
true, JRuby.runtime.jruby_class_loader)

That should fix the problem.

As for the JRuby proper, I’ll let Charlie decide, whether to keep the
current behavior or to revert that commit, or something inbetween.

Thanks,
–Vladimir

On Fri, May 14, 2010 at 2:53 PM, Christopher Dancy
[email protected] wrote:

include_package ‘java.sql’
jdbc:sqlserver://:;databaseName=

This code works perfectly fine under jruby 1.4 but craps out under jruby
1.5. Just wondering if something changed in the way of loading java
libs?


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hi Christopher,

Could you try to run your script with -Xnobootclasspath option.

jruby -Xnobootclasspath …

Any difference? I assume you’re on Windows, right?

Thanks,
–Vladimir

On Fri, May 14, 2010 at 2:53 PM, Christopher Dancy
[email protected] wrote:

include_package ‘java.sql’
jdbc:sqlserver://:;databaseName=

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Vladimir S. wrote:

Hi Christopher,

I bisect the problem to the following commit:

commit 61a000f7d152ce79c90a03ea33ab3e357aaca9bc
Date: Sun Apr 11 15:54:21 2010 -0500
When loading classes for JI, don’t force them to initialize right away
(needed for compilers, etc, where class will never actually be
executed).

So, basically, doing java_import does not initialize the class
anymore, hence JDBC can’t find the driver.

As a workaround, I could recommend the following:
require ‘jruby’
java.lang.Class.for_name(“com.microsoft.sqlserver.jdbc.SQLServerDriver”,
true, JRuby.runtime.jruby_class_loader)

That should fix the problem.

As for the JRuby proper, I’ll let Charlie decide, whether to keep the
current behavior or to revert that commit, or something inbetween.

Thanks,
–Vladimir

On Fri, May 14, 2010 at 2:53 PM, Christopher Dancy
[email protected] wrote:

�include_package ‘java.sql’
jdbc:sqlserver://:;databaseName=

This code works perfectly fine under jruby 1.4 but craps out under jruby
1.5. Just wondering if something changed in the way of loading java
libs?


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Vladimir,

 Thanks for looking into this and yes your solution worked. The only 

change I had to make was in referencing java’s DriverManager. Which went
from:

JavaSql::DriverManager.getConnection("jdbc:sqlserver://:;databaseName=

to:

DriverManager.getConnection("jdbc:sqlserver://:;databaseName=

Exceptions were thrown looking for JavaSql, so I removed it and
everything fine now. Thanks.

Hi Christopher, Aidy,

On Mon, May 17, 2010 at 3:32 PM, Christopher Dancy
[email protected] wrote:

Vladimir,

Thanks for looking into this and yes your solution worked.

Glad to hear that. So this is not a blocker at least.

Meanwhile, I’ve filed the bug, so that we won’t forget about it:
http://jira.codehaus.org/browse/JRUBY-4795

Thanks,
–Vladimir


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email