Monkeybars and jdbc-mysql

Hello,
I’m writting an desktop app using Monkeybars, and need like to connect
to a
MySQL database.

The problem is that I can’t get the jdbc-mysql to work with Monkeybars.

I’ve posted the following question in the Monkeybars forum that explains
the
problem in more detail:
http://kenai.com/projects/monkeybars/forums/forum/topics/1747-Using-sequel-and-jdbc-mysql-gems-in-a-monkeybar-app#p4824

I’m using JRuby 1.3.1, Monkeybars 1.0.4 and the latest jdbc-mysql
installed
via rubygems.

Connecting to a MySQL database should not be that dificult, so I think
I’m
missing something here.

Anyone?

Hi Luiz,

So, can you connect to the database from standalone code, not from the
Monkeybars application? Please, confirm.

If you can from standalone, but can’t from your application, this
might be due to classloader magic…
See JRUBY-2495 for more details.

And try to add these lines and see how it goes (and let us know too):

require ‘jruby’
java.lang.Thread.currentThread.setContextClassLoader(JRuby.runtime.jruby_class_loader)

Thanks,
–Vladimir

2009/10/14 Luiz Fernando Signorelli Gonçalves [email protected]:

missing something here.
Anyone?


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hi Vladmir,
Yes, I can connect to the database from standalone code.
I will check the isssue, add those two lines and report the results
later.

Thanks for the help.


Luiz Fernando Signorelli

So I just did a bunch of tests, none with good results.
I have this code in the ‘main.rb’ file of my Monkeybars application:

require ‘jruby’
java.lang.Thread.currentThread.setContextClassLoader(JRuby.runtime.jruby_class_loader)
conn_string = “jdbc:mysql://localhost/bjj?user=root&password=root”
conn = java.sql.DriverManager.get_connection(conn_string)

I’ve ran the code with the mysql driver in the classpath and requireing
‘jdbc-mysql’ gem.
I’ve ran it with two lines from Vladmir and without it.
I’ve ran it from Netbeans and from the command line.
Every time I get the same error: NativeException -
java.sql.SQLException:
No suitable driver found for
jdbc:mysql://localhost/bjj?user=root&password=root

I don’t know if it makes any difference, but I’m trying this on a
Windows
machine.

Anyone can give me a light on this?

Thanks,

Luiz Fernando Signorelli

2009/10/14 Luiz Fernando Signorelli Gonçalves [email protected]

I also did see these errors recently.

first thing I would do to enable debugging on the DriverManager

java.sql.DriverManager.setLogStream(java.lang.System.err)

the reason is basically that the driver manager registers the driver
on per class-loader base.

what happens if you put mysql driver in the classpath and NOT
requiring ‘jdbc-mysql’ gem ?

does it work if you just load the driver class before going to the
DriverManager like
java.lang.Thread.currentThread.getContextClassLoader().loadClass(“com.mysql.jdbc.Driver”,
true).newInstance

another trick which worked for the dataobjects project was using
java_import “com.mysql.jdbc.Driver”
after requiring ‘jdbc/mysql’

maybe something helps, Kristian

2009/10/14 Luiz Fernando Signorelli Gonçalves [email protected]:

Every time I get the same error:Â NativeException - java.sql.SQLException: No

Hi Luiz,
require ‘jruby’

MySQL database.
I’m


Kristian Meier + Saumya Sharma + Sanuka Meier
Vadakkethu House,
Edayanmula West PO - 689532,
Pathanamthitta District, Kerala, INDIA

tel: +91 468 2319577

protect your privacy while searching the net: www.ixquick.com

         _=_
       q(-_-)p
        '_) (_`
        /__/  \
     _(<_   / )_
  (__\_\_|_/__)

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hi Kristian,
Enabling the log on DriverManager gives me this:

DriverManager.getConnection(“jdbc:mysql://localhost/bjj?user=root&password=root”)
trying
driver[className=sun.jdbc.odbc.JdbcOdbcDriver,[email protected]
]
*Driver.connect (jdbc:mysql://localhost/bjj?user=root&password=root)
skipping:
driver[className=com.mysql.jdbc.Driver,[email protected]]
getConnection: no suitable driver found for
jdbc:mysql://localhost/bjj?user=root&password=root
java.sql.SQLException: No suitable driver found for
jdbc:mysql://localhost/bjj?user=root&password=root

– StackTrace omitted

It shows that the mysql driver is skipped, and looking at the
DriverManager
source code http://www.docjar.com/html/api/java/sql/DriverInfo.java.html
(line
261) it seams like it’s a classloader problem indeed.

Your other sugestions did not work either.

I think we are getting closer, maybe someone from the Monkeybars team
can
clarify this.

Thanks,

Luiz Fernando Signorelli

2009/10/14 Luiz Fernando Signorelli Gonçalves [email protected]:

java.sql.SQLException: No suitable driver found for
jdbc:mysql://localhost/bjj?user=root&password=root
– StackTrace omitted
It shows that the mysql driver is skipped, and looking at the DriverManager
source
code http://www.docjar.com/html/api/java/sql/DriverInfo.java.html (line 261)
it seams like it’s a classloader problem indeed.
Your other sugestions did not work either.
I think we are getting closer, maybe someone from the Monkeybars team can
clarify this.

I suspect you’re running into the limitation of DriverManager that it
will only load and recognize JDBC drivers from the boot classpath. In
AR-JDBC we work around this by constructing a Driver instance directly
and bypassing DriverManager 1.

/Nick


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Wed, Oct 14, 2009 at 2:58 PM, Nick S. [email protected]
wrote:

skipping:

/Nick

You are right Nick, the workaround solved the problem.

My original idea was to use Sqeuel, but it has the same problem, as we
can
see here:
http://github.com/jeremyevans/sequel/blob/master/lib/sequel/adapters/jdbc.rb#L141-146

I’ll try to come up with a patch to Sequel’s Jdbc Adapter.

Thanks everybody for the help.

Hi Nick,

On Wed, Oct 14, 2009 at 7:58 PM, Nick S. [email protected]
wrote:

I suspect you’re running into the limitation of DriverManager that it
will only load and recognize JDBC drivers from the boot classpath. In
AR-JDBC we work around this by constructing a Driver instance directly
and bypassing DriverManager 1.

/Nick

Now you got me confused. :slight_smile:

If the DriverManager only loads drivers from the bootclasspath, then
how come this code actually works:

http://pastie.org/655965

No classpath or bootclasspath was changed for it to work. I think that
the DriverManager can load the drivers not only from the
bootclasspath, but from the context classloader as well, but I might
be wrong. But then again, the code above works with no bootclasspath
changes.

Thanks,
–Vladimir


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

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