簡體   English   中英

如何在jruby中使用java.util.properties?

[英]How can I use java.util.properties in jruby?

我正在使用此網站上提供的課程: 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中創建屬性並將其傳遞掛了電話。 有任何想法嗎?

java.util.Properties Java類像Ruby一樣對待(所有API方法都可用)

同樣,如果您查看docs 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM