简体   繁体   中英

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

I'm setting up SSL and I need to pass a list of java.util.properties to Driver manager.

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. Any ideas?

treat the java.util.Properties Java class like a Ruby one (all of its API methods are available)

also if you look at the docs Properties extends Hashtable and Hashtable is a (implements) Map .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM