简体   繁体   English

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

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

I'm working with a class provided on this site: https://www.oracle.com/technetwork/articles/dsl/jruby-oracle11g-330825.html 我正在使用此网站上提供的课程: https : //www.oracle.com/technetwork/articles/dsl/jruby-oracle11g-330825.html

I'm setting up SSL and I need to pass a list of java.util.properties to Driver manager. 我正在设置SSL,并且需要将java.util.properties列表传递给驱动程序管理器。

I figure I do something like this... 我想我做这样的事情...

# 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

I'm hung up on how to create the properties in ruby and pass them. 我对如何在ruby中创建属性并将其传递挂了电话。 Any ideas? 有任何想法吗?

treat the java.util.Properties Java class like a Ruby one (all of its API methods are available) java.util.Properties Java类像Ruby一样对待(所有API方法都可用)

also if you look at the docs Properties extends Hashtable and Hashtable is a (implements) Map . 同样,如果您查看docs Properties extends Hashtable并且Hashtable是一个(实现) Map

JRuby provides extension for all map types to act very much like a Ruby Hash . 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