Category Archives: Uncategorized - Page 2

How to Setup Global JNDI Mapping for Oracle JDBC Connection Pooling with Tomcat

 Making a User Dependent Connection so we could realize the so called connection proxy.

  •  Setup the server.xml file without the username and password
Setup the server.xml file with an entry without the username and password specified as shown in the example below:
 
<Resource name="jdbc/db2"
auth="Container"
type="oracle.jdbc.pool.OracleDataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
factory="oracle.jdbc.pool.OracleDataSourceFactory"
url="jdbc:oracle:thin:@oracle.microdeveloper.com:1521:db2"
maxActive="20"
maxIdle="10"
maxWait="-1" />
 
  •  Add code to the class to set the username and password
In the class, before the connection is formed, add a call to the datasource to set the username and password. This can be done in one of two ways as shown below:
try {
Context initContext = new InitialContext();
Context envContext = (Context) initContext.lookup(”java:/comp/env”);
OracleDataSource ds = (OracleDataSource) envContext.lookup(”jdbc/db2″);

   if (envContext == null) throw new Exception(”Error: No Context”);
   if (ds == null) throw new Exception(”Error: No DataSource”);
   if (ds != null){
      ds.setUser(”scott”);
      ds.setPassword(”tiger”);
      conn = ds.getConnection();
   } catch (Exception e) {
  e.printStackTrace();
}
- or -
try {
Context initContext = new InitialContext();
Context envContext = (Context) initContext.lookup(”java:/comp/env”);
OracleDataSource ds = (OracleDataSource) envContext.lookup(”jdbc/db2″);

   if (envContext == null) throw new Exception(”Error: No Context”);
   if (ds == null) throw new Exception(”Error: No DataSource”);
   if (ds != null){
      conn = ds.getConnection(”scott”,”tiger”);
   } catch (Exception e) {
  e.printStackTrace();
}
We can now supply different user credentials fro each connection
 
This method has been tested on Oracle 8.1.6 through 10.0.1 and Tomcat 5.0.28, 5.5.4, 5.5.7, and 5.5.9.

Installing Embedded JBoss into Standalone Tomcat 6.0

Installing Embedded JBoss into Standalone Tomcat 6.0

 

  1. Copy all files and directories under embedded-jboss/bootstrap into tomcat’s lib/ directory, except the jndi.properties file
  2. Copy all .jar files under embedded-jboss/lib into tomcat’s lib/ directory
  3. Remove the lib/annotations-api.jar file. Tomcat 6.0 erroneously puts PersistenceContextType? as an inner class of the @PersistenceContext? annotation.

 After installation, your tomcat distribution should look something like this:


apache-tomcat-6.0.13/
              lib/
                       conf/
                       deploy/
                       deployers/
                       log4j.xml
                       thirdparty-all.jar
                       hibernate-all.jar
                       jboss-embedded-all.jar
                       … all the other jars

 NOTE: If you cannot get log out of libraries that depend on commons-logging (i.e, hibernate), it may be that your system is using NoOpLog?. Try creating a lib/commons-logging.properties and define the property: org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogg

Tags: ,