Skip to content

Instantly share code, notes, and snippets.

@marklocklear
Last active September 25, 2015 01:58
Show Gist options
  • Save marklocklear/844260 to your computer and use it in GitHub Desktop.
Save marklocklear/844260 to your computer and use it in GitHub Desktop.
jruby and mysql
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