Created
March 14, 2011 14:40
-
-
Save marklocklear/869218 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'java' | |
require 'rubygems' | |
require 'jdbc/mysql' | |
module JavaLang | |
include_package "java.lang" | |
end | |
module JavaSql | |
include_package 'java.sql' | |
end | |
begin | |
com.mysql.jdbc.Driver.new | |
conn = JavaSql::DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/sandbox", "root", "password"); | |
stmt = conn.createStatement | |
rs = stmt.executeQuery("select * from states") | |
while (rs.next) do | |
puts rs.getString("name") | |
end | |
rs.close | |
stmt.close | |
conn.close() | |
rescue JavaLang::ClassNotFoundException | |
puts "ClassNotFoundException" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment