Getting JRuby to talk to MySQL can be a reall PIA. Heres what you do.
First install the jdbc-mysql gem in JRuby. You do this by using the -S flag for JRuby. This goes for all gem commands. So to install this gem you would type 'jruby -S gem install jdbc-mysql'. As another example if you want to list your gems installed in JRuby you'd do 'jruby -S gem list'. Get the idea?
The way I'm making calls to mysql is by using a wrapper. I'm calling this mysql_helper.rb, and it looks like this:
Notice our require statement from the jdbc-mysql driver. Note the syntax is a little silly. While the gem itself is called jdbc-mysql, when we actually reference it with a require statement, we use jdbc/mysql.
Now to actually call this we just 'require' the mysql_helper.rb file in whatever script we are running.
Heres a self contained script:
So heres what the code would actually look like to do some stuff in your database using ruby and jruby.
No comments:
Post a Comment