调用oracle存储过程后连接断了_oracle存储过程会怎样运行,ruby调用oracle存储过程实例之oracle连接配置...

先看一下ruby怎样连接oracle数据库:

class External < ActiveRecord::Base

self.abstract_class = true

establish_connection :wifi_rms

end

abstract_class 抽象类:抽象类是不允许实例化的类,因此一般它需要被进行扩展继承。

从establish_connection 进去可见:class ConnectionSpecification类

定义了这个连接查找方法:

def self.establish_connection(spec = nil)

case spec

when nil

raise AdapterNotSpecified unless defined? RAILS_ENV

establish_connection(RAILS_ENV)

when ConnectionSpecification

@@connection_handler.establish_connection(name, spec)

when Symbol, String

if configuration = configurations[spec.to_s]

establish_connection(configuration)

else

raise AdapterNotSpecified, "#{spec} database is not configured"

end

else

......

end

这里传入的是database.yml中配置的参数

wifi_rms:

adapter: oracle

database: (DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = "your ip")(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = "your service")(SERVER = DEDICATED)))

username: name

password: password

encoding: utf8

host: host_ip

service: your_service

这样当你要调用oracle库关联的时候直接继承连接类即可实现类持久化到oracle数据库

class ConvenientReportMonth < External

#继承External类

#关联表设置

set_table_name "CONVENIENT_REPORTS_MONTH"

#表序列设置

set_sequence_name "seq_convenient_month_id"

end

最后要说一下的是:

由于rails生产模式下配置的是mysql数据库

development: &config

adapter: mysql

encoding: utf8

database: db_new

username: root

password: password

socket: /tmp/mysql.sock

host: your_ip

port: 3306

因此需要调用mysql库的时候只要集成

class Event < ActiveRecord::Base

#ActiveRecord::Base默认连接库为mysql

end

至此,实现了rails项目中mysql和oracle双库开发工作环境。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值