Created
November 19, 2012 08:08
-
-
Save daicham/4109527 to your computer and use it in GitHub Desktop.
A sample ruby code of executing SQL for Oracle
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
# encoding: utf-8 | |
# | |
# Prerequisite: | |
# gem install ruby-oci8 | |
require 'oci8' | |
def log(message) | |
puts "#{Time.now.strftime("%Y-%m-%d %H:%M:%S")} #{message}" | |
end | |
log "connecting..." | |
conn = OCI8.new("hoge", "hoge_passwd", "//localhost/db") | |
log "connected." | |
begin | |
num = conn.exec("insert into ...") | |
conn.commit | |
log "#{num} inserted." | |
ensure | |
log 'logging off...' | |
conn.logoff | |
log 'logged off.' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment