------ art_40719_13801747.1178273832048 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 5/4/07, Ronny <ro.naldfi.scher / gmail.com> wrote: > > 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 > > 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 avaSql::DriverManager.getConnection("jdbc:odbc:DSN"); stmt onn.createStatement rs tmt.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 Talim http://rubylearning.com/ ------ art_40719_13801747.1178273832048--