Skip to content

Instantly share code, notes, and snippets.

@tillsc
Created December 7, 2012 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tillsc/4233025 to your computer and use it in GitHub Desktop.
Save tillsc/4233025 to your computer and use it in GitHub Desktop.
Defining a JNDI OracleConnectionPool in JRuby for testing purposes
if RUBY_PLATFORM =~ /java/
require 'java'
# Add ojdbc to the Java classpath
$CLASSPATH << File.expand_path('../../lib/ojdbc5.jar', __FILE__)
# Simply add all apache tomcat libs (some juli.jar might need to be added too)
Dir.glob("/usr/local/Cellar/apache-tomcat/6.0.24/lib/*.jar") do |filename|
$CLASSPATH << filename
end
# Where are the TNSNAMES.ora?
java.lang.System.setProperty("oracle.net.tns_admin", "/opt/oracle/network/admin")
java.lang.System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"org.apache.naming.java.javaURLContextFactory")
java.lang.System.setProperty(javax.naming.Context.URL_PKG_PREFIXES,
"org.apache.naming")
ic = javax.naming.InitialContext.new
ic.createSubcontext("java:")
ic.createSubcontext("java:comp")
ic.createSubcontext("java:comp/env")
ic.createSubcontext("java:comp/env/jdbc")
ds = Java::oracle.jdbc.pool.OracleConnectionPoolDataSource.new
ds.setURL("jdbc:oracle:thin:@SID")
ds.setUser("USER")
ds.setPassword("PASSWORD")
ic.bind("java:comp/env/jdbc/myCoolName", ds)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment