Last active
September 25, 2015 01:58
-
-
Save marklocklear/844260 to your computer and use it in GitHub Desktop.
jruby and mysql
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/clist", "root", "password"); | |
stmt = conn.createStatement | |
rs = stmt.executeQuery("select * from post") | |
while (rs.next) do | |
puts rs.getString("post_location") | |
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