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.
http://rubylearning.com/