使用Ruby连接到Oracle DB [英] Connecting to Oracle DB using Ruby

查看:148
本文介绍了使用Ruby连接到Oracle DB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我坚持连接到Oracle数据库,读取了大量的东西,但没有帮助结果。

我有远程Oracle数据库,我使用DBVisualizer设置连接连接到这样:

I am stuck with connecting to Oracle DB, have read lots of stuff but no help on result.
I have remote Oracle DB, I am connecting to it using DBVisualizer setting connection like this:

DB Type : Oracle
Driver (jdbc) : Oracle thin
Database URL: jdbc:oracle:thin:@10.10.100.10:1521/VVV.LOCALDOMAIN
UserIdf: SomeUser
Pass: SomePass

连接工作正常。

我在Ruby做的是:

require 'oci8'
require 'dbi'
...

conn = OCI8.new('SomeUser','SomePass','//10.10.100.10:1521/VVV.LOCALDOMAIN')
...

/ p>

What I get is:

ORA-12545: Connect failed because target host or object does not exist
oci8.c:360:in oci8lib.so


推荐答案

第三个参数需要是TNS主机名,如果使用SQL plus,它也是connectstring中的第三个参数,您也可以在oracle maps中的tnsnames.ora文件中找到它

the third parameter needs to be the TNS hostname, if you use SQL plus it is also the third parameter in the connectstring, you can find it also in the tnsnames.ora file in the oracle maps

在SQLPlus :连接用户/密码@ hostname;

in oci8: conn = OCI8.new('SomeUser','SomePass',hostname)

in SQLPlus : connect user/password@hostname;
in oci8 : conn = OCI8.new('SomeUser','SomePass',hostname)

这里是一个工作示例,模糊了当然的参数

Here a working sample, obfuscated the parameters of course

require 'oci8'
oci = OCI8.new('****','***','****.***')
oci.exec('select * from table') do |record|
  puts record.join(',')
end

这篇关于使用Ruby连接到Oracle DB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆