Monday, May 03, 2010

Yucks --- see the nasty way of initializing the jdbc driver. all the examples on the web are wrong...
I had to get this from a forum post!


#!/Users/spicysquid/java/jruby/jruby-1.5.0.RC2/bin/jruby
require 'java'
require 'rubygems'
require 'jdbc/mysql'

#this isnt needed since we have jdbc/mysql already loaded
#require './mysql-connector-java-5.0.5.jar'
#import 'com.mysql.jdbc.Driver'

begin
#Nasty way of loading the jdbc driver
java.lang.Thread.currentThread.getContextClassLoader().loadClass("com.mysql.jdbc.Driver",true).newInstance

conn = java.sql.DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/database", "root", "");
stmt = conn.createStatement
rs = stmt.executeQuery("select * from member")
while (rs.next) do
puts rs.getString("username")
end
rs.close
stmt.close
conn.close()
end

No comments: