Home > Database > Mysql Tutorial > Rails 连接 Oracle 数据库

Rails 连接 Oracle 数据库

WBOY
Release: 2016-06-07 17:02:47
Original
1005 people have browsed it

在安装过程可能会出错,一般都会有提示,可能会执行下面步骤 2.1)sudo ln -s libclntsh.dylib.10.1 libclntsh.dylib 2.2)设置环境

准备工作:
1)安装 ActiveRecord Oracle adapter
sudo gem install activerecord-oracle-adapter --source

2)安装 Oracle Client

在安装过程可能会出错,一般都会有提示,可能会执行下面步骤
 2.1)sudo ln -s libclntsh.dylib.10.1 libclntsh.dylib
 2.2)设置环境变量,Mac下可在.profile增加
export DYLD_LIBRARY_PATH="/usr/local/oracle/instantclient_10_2"

3)安装ruby oracle驱动,,要根据自己系统环境修改
sudo env DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH ARCHFLAGS="-arch x86_64" gem install ruby-oci8

安装参考下面文章:

项目需要Rails应用同时连接mysql与 Oracle DB,所以只要在config/database.yml文件中修改配置:
下面的配置一般默认情况使用'development'的配置,及连接sqlite3数据库。

development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

iisp:
  adapter: oracle
  encoding: utf8
  database: 192.168.68.22/iisp.xjgz
  username: iisp916
  password: iisp916

其中iisp/database中,IP地址后面跟的是数据库的Sid,不是数据库名

model要连接oracle时,在model中增加下面代码:

establish_connection 'iisp'
self.table_name = 't_capacity'
self.sequence_name = 's_capacity' # 主键生成

设置Rails连接Oracle的编码:
config/environment.rb中增加下面代码
ENV['NLS_LANG'] = 'AMERICAN_AMERICA.UTF8'

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template