Using sequel and jdbc-mysql gems in a monkeybar app

  6 posts   Feedicon  
Replies: 5 - Last Post: November 06, 2009 14:28
by: Logan Barnett
showing 1 - 6 of 6
 
Posted: October 13, 2009 19:50 by luizsignorelli
Hello,

I'm trying to use this two gems in my app, but I'm running into an error.

First of all, I don't know the right way to use gems with monkeybar. Here is what I did to be able to run the app from Netbeans:

1. Installed the gems in JRuby: jruby -S gem install sequel jdbc-mysql

2. Unpacked the gems in myapp/lib/ruby: jruby -S gem unpack sequel jdbc-mysql

3. In my manifest.rb, I add the unpacked gems to the load path:

case Monkeybars::Resolver.run_location
when Monkeybars::Resolver::IN_FILE_SYSTEM
# Files to be added only when running from the file system go here
add_to_load_path "../lib/ruby/sequel/lib"
add_to_load_path "../lib/ruby/jdbc-mysql/lib"
when Monkeybars::Resolver::IN_JAR_FILE
# Files to be added only when run from inside a jar file
end


4. Now I tryed to create a table in the database (The same code works if I run int outside of the monkeybar app):

require 'sequel'
DB = Sequel.connect('jdbc:mysql://localhost/bjj?user=root&password=root')
DB.create_table :teams do
primary_key :id
String :name
end

The first two lines work, but the create_table gives me this error:
Sequel:GrinatabaseConnectionError - NativeException: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/bjj?user=root&password=root



I think the problem may be related with the way I added the gems to the app. Am I doing it wrong?

Anyone knows where the problem may be?

Tanks

 
Posted: October 13, 2009 20:50 by luizsignorelli
I just did another test, and it seams like the problem is on the jdbc-mysql gem.

The folowing code throws the same exception:


require 'jdbc/mysql'
include_class "com.mysql.jdbc.Driver"

com.mysql.jdbc.Driver
conn_string = "jdbc:mysql://localhost/bjj?user=root&password=root"
DB = java.sql.DriverManager.getConnection(conn_string)


Note that I did not use Sequel this time.

So, anyone knows how to connect to a MySQL database using the jdbc-mysql gem in a Monkeybars app?
 
Posted: October 14, 2009 15:54 by Logan Barnett

Have you seen these resources in our Wiki? http://kenai.com/projects/monkeybars/pages/UseRubyGemsInYourApplication

This part isn't so clear http://kenai.com/projects/monkeybars/pages/HookUpADatabase but it mentions that any jars in your gems, including the JDBC driver, need to be placed in lib/java.

Our wiki can always use some more love! Please post any findings to our wiki (:

 
Posted: October 14, 2009 16:44 by luizsignorelli
I've seen the wiki, but that's for running the app in a jar, isn't it? I'm just trying to run it from Netbeans.
Anyway, I've placed the driver in lib/java but the error persists.

I've posted this issue in the jruby-user mailling list and it seams like it's a classloader problem: http://www.ruby-forum.com/topic/197260

I don't know what to do anymore, so I'm giving up on this for now, but id like to help get this fixed. Let me know if there's anything more I cando to help.

Monkeybars is great, but connecting to a relational database should not be so complicated.


Thanks
 
Posted: October 15, 2009 14:13 by luizsignorelli
The guys on the jruby-user mailling list helped me to solve this issue.

There is a limitation on the DriverManager that it will only load and recognize JDBC drivers from the boot classpath.
I don't know if there's anything Monkeybars can do about it, but there is a workaround used on activerecord-jdbc that works fine.

You have to create an instance of the jdbc driver and get the connection through it, and not through the DriverManager.
For more information see the malling list thread (link on my last post).


Maybe we could add this to the wiki.
 
Posted: November 06, 2009 14:28 by Logan Barnett

If you could toss that in the wiki somewhere, that would be awesome!

showing 1 - 6 of 6
Replies: 5 - Last Post: November 06, 2009 14:28
by: Logan Barnett
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close