Create a gist now

Instantly share code, notes, and snippets.

jruby+db2
#!/usr/bin/env ruby
# coding: UTF-8
require "./db2jcc4.jar"
require "./db2jcc_license_cu.jar"
query = <<-eos
select 'hello' as foo, 'world' as bar
from sysibm.sysdummy1
eos
begin
Java::com.ibm.db2.jcc.DB2Driver
options = {
adapter: 'jdbc',
username: '<username>',
password: '<secret>',
driver: 'com.ibm.db2.jcc.DB2Driver',
url: 'jdbc:db2:[<//host>[:<5432>/]]<database>'
}
connSelect = java.sql.DriverManager.get_connection options[:url], options[:username], options[:password]
stmtSelect = connSelect.create_statement
rsS = stmtSelect.execute_query query
while (rsS.next) do
puts rsS.getObject(1)
puts rsS.getObject('foo')
end
end
stmtSelect.close
connSelect.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment