How to connect to oracle with jruby

Hi,

My version of jruby is:
jruby 9.2.8.0 (2.5.3) 2019-08-12 a1ac7ff OpenJDK 64-Bit Server VM 25.212-b04 on 1.8.0_212-b04 +indy +jit [linux-x86_64]

I want to connect to an Oracle database.
A jdbc gem is installed.
Do I need additional things to install?
I’d rather not install the complete Oracle Client software.

To connect to a SQLServer database I used
require “jdbc/mssql”

And I have the following:
jdbc (0.1.1 java)
jdbc-mssql (0.7.0 java)

What is the best way (the least amount of maintenance)?

Regards Hans

Turns out it is relatively simple:
You need a ojdbc8 jar and include it.

require ‘java’
require “/u01/apps//lib/jars/ojdbc8-19.3.0.0.jar”

java_import 'java.sql.DriverManager

user = 'system
password = ‘manger’
sql_statement = ‘select * from dual’
connect_string = ‘(DESCRIPTION=(SOURCE_ROUTE=OFF)(ADDRESS_LIST=(ADDRESS=PROTOCOL=TCP)(HOST=saturn)(PORT=1521)))(CONNECT_DATA=(SID=MOON)(SRVR=DEDICATED)))’

connection = java.sql.DriverManager.getConnection(
“jdbc:oracle:thin:@” + connect_string,
user,
password
)
statement = connection.create_statement
results=statement.execute_query(sql_statement)

while(results.next())
puts rs.getObject(1)
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs