Created
January 4, 2016 10:57
-
-
Save jbgutierrez/45c2a4aae55f0a8cb24e to your computer and use it in GitHub Desktop.
jruby+db2
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
#!/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