Created
December 7, 2012 12:42
-
-
Save tillsc/4233025 to your computer and use it in GitHub Desktop.
Defining a JNDI OracleConnectionPool in JRuby for testing purposes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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