require 'java'
module JavaLang
include_package "java.lang"
end
module JavaSql
include_package 'java.sql'
end
begin
JavaLang::Class.forName("com.mysql.jdbc.Driver").newInstance
conn = JavaSql::DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/
stmt = conn.createStatement
rs = stmt.executeQuery("select name from user")
while (rs.next) do
puts rs.getString("name")
end
rs.close
stmt.close
conn.close()
rescue JavaLang::ClassNotFoundException
puts "ClassNotFoundException"
rescue JavaSql::SQLException
puts "SQLException"
end
Share & Learn
Friday, June 22, 2007
The Code snippet for MySQL using JRuby
blog comments powered by Disqus
Subscribe to:
Post Comments (Atom)