我正在使用此网站上提供的课程:https://www.oracle.com/technetwork/articles/dsl/jruby-oracle11g-330825.html
我正在设置SSL,我需要将java.util.properties列表传递给驱动程序管理器。
我认为我做这样的事...
# jdbc_connection.rb
require 'java'
java_import 'oracle.jdbc.OracleDriver'
java_import 'java.sql.DriverManager'
java_import 'java.util.Properties' #<---Import here
class OracleConnection
@conn = nil
def initialize (url)
@url = url
#I want to create the array of properties here and populate it with my SSL properties. I'm really lost here.
# Load driver class
oradriver = OracleDriver.new
DriverManager.registerDriver oradriver
#I want to pass the Properties to DriverManager.
@conn = DriverManager.get_connection url, properties
@conn.auto_commit = false
end
我想知道如何在ruby中创建属性并传递它们。有什么想法吗?
答案 0 :(得分:1)
像Ruby一样处理java.util.Properties
Java类(所有API方法都可用)
如果您查看文档Properties extends Hashtable
,并且Hashtable是Map
(实现),也是
。
JRuby为所有地图类型提供了扩展,使其非常像Ruby Hash
。
properties = java.util.Properties.new
properties.put 'a.ssl.key', 'A-VALUE' # Java style (put inherited from Hashtable)
properties['another.ssl.key'] = 'ANOTHER' # Ruby Hash style