How to connect from JRuby to a MySql database?

Could someone kindly sketch an example (or point me to a related
website), how
to query a MySql database from JRuby?

I guess there are several possibilities available (via JDBC, since
JRuby is based on
Java, and maybe using some Ruby library too, since JRuby is intended
to be compatible
to Ruby), but I didn’t find any documentation for it on the web.

Ronald

On 5/4/07, Ronny [email protected] wrote:

Ronald

Here’s an example of accessing a MS-Access database table using JRuby.
You
can make the relevant changes for mySQL.

require ‘java’
module JavaLang
include_package “java.lang”
end
module JavaSql
include_package ‘java.sql’
end

begin
JavaLang::Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”)
conn = JavaSql::DriverManager.getConnection(“jdbc:odbc:DSN”);
stmt = conn.createStatement
rs = stmt.executeQuery(“select studname from student”)
while (rs.next) do
puts rs.getString(“studname”)
end
rs.close
stmt.close
conn.close()
rescue JavaLang::ClassNotFoundException
puts “ClassNotFoundException”
rescue JavaSql::SQLException
puts “SQLException”
end

Hope this helps.

Satish T.

On 5/4/07, Ronny [email protected] wrote:

Ronald

You can refer to my blog post here -

Satish T.