Skip to content

Commit dbf19f3

Browse files
yahondaclaude
andcommitted
Add modern JDBC driver support (ojdbc17, ojdbc11, ojdbc8)
Build the JDBC driver search list based on the running Java major version so that only compatible jars are tried, in priority order preferring the newest driver. Older drivers are still searched as fallbacks since they run on newer Java versions. - ojdbc17.jar for Java 17+ - ojdbc11.jar for Java 11+ - ojdbc8.jar for Java 8+ Use Regexp.union to escape dots in jar name matching to avoid unintended classpath matches. Ref: https://www.oracle.com/database/technologies/appdev/jdbc-downloads.html Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5ea974a commit dbf19f3

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ In addition install either ruby-oci8 (for MRI/YARV) or copy Oracle JDBC driver t
154154
If you are using MRI Ruby implementation then you need to install ruby-oci8 gem (version 2.1 or higher)
155155
as well as Oracle client, e.g. [Oracle Instant Client](http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html).
156156

157-
If you are using JRuby then you need to download latest [Oracle JDBC driver](http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html) - either ojdbc7.jar for Java 8 and 7, ojdbc6.jar for Java 6, 7, 8 or ojdbc5.jar for Java 5. You can refer [the support matrix](http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-faq-090281.html#01_03) for details.
157+
If you are using JRuby then you need to download latest [Oracle JDBC driver](https://www.oracle.com/database/technologies/appdev/jdbc-downloads.html) - ojdbc17.jar for Java 17+, ojdbc11.jar for Java 11+, or ojdbc8.jar for Java 8+.
158158

159159
And copy this file to one of these locations. JDBC driver will be searched in this order:
160160

lib/plsql/jdbc_connection.rb

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@
22
require "java"
33
require "jruby"
44

5-
# ojdbc6.jar or ojdbc5.jar file should be in JRUBY_HOME/lib or should be in ENV['PATH'] or load path
5+
# Oracle JDBC driver jar should be in JRUBY_HOME/lib or should be in ENV['PATH'] or load path
66

77
java_version = java.lang.System.getProperty("java.version")
8-
ojdbc_jars = if java_version =~ /^1.5/
9-
%w(ojdbc5.jar)
10-
elsif java_version =~ /^1.6/
11-
%w(ojdbc6.jar)
12-
elsif java_version >= "1.7"
13-
# Oracle 11g client ojdbc6.jar is also compatible with Java 1.7
14-
# Oracle 12c client provides new ojdbc7.jar
15-
%w(ojdbc7.jar ojdbc6.jar)
8+
java_major = if java_version =~ /^1\.(\d+)/
9+
$1.to_i
1610
else
17-
[]
11+
java_version.to_i
1812
end
1913

20-
if ENV_JAVA["java.class.path"] !~ Regexp.new(ojdbc_jars.join("|"))
14+
ojdbc_jars = []
15+
ojdbc_jars << "ojdbc17.jar" if java_major >= 17
16+
ojdbc_jars << "ojdbc11.jar" if java_major >= 11
17+
ojdbc_jars << "ojdbc8.jar" if java_major >= 8
18+
ojdbc_jars << "ojdbc7.jar" if java_major >= 7
19+
ojdbc_jars << "ojdbc6.jar" if java_major >= 6
20+
ojdbc_jars << "ojdbc5.jar" if java_major == 5
21+
22+
if ENV_JAVA["java.class.path"] !~ Regexp.union(ojdbc_jars)
2123
# On Unix environment variable should be PATH, on Windows it is sometimes Path
2224
env_path = (ENV["PATH"] || ENV["Path"] || "").split(File::PATH_SEPARATOR)
2325
# Look for JDBC driver at first in lib subdirectory (application specific JDBC file version)

0 commit comments

Comments
 (0)