Database Connection Pooling with Tomcat 6.0.18 and Oracle 10g
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   prasenjit_biswas
Posted On:   Saturday, June 13, 2009 04:53 AM

Hi, I have been facing problem for quite few days in making Connection Pool with Tomcat 6.0.18 and Oracle 10g. I have tried all suggestions from net search. Nothing had worked, in stead I get confused with different suggestions in diferent sites. Here is my problem: I am getting following error javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.commons.dbcp.BasicDataSourceFactory [Root exception is java.lang.ClassCastException: org.apache.commons.dbcp.BasicDataSourceFactory cannot be cast to javax.naming.spi.InitialContextFactory] at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)    More>>

Hi,

I have been facing problem for quite few days in making Connection Pool with Tomcat 6.0.18 and Oracle 10g. I have tried all suggestions from net search. Nothing had worked, in stead I get confused with different suggestions in diferent sites.



Here is my problem: I am getting following error



javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.commons.dbcp.BasicDataSourceFactory [Root exception is java.lang.ClassCastException: org.apache.commons.dbcp.BasicDataSourceFactory cannot be cast to javax.naming.spi.InitialContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.InitialContext. (InitialContext.java:197)
at utility.DataBaseConTest.callDatabase(DataBaseConTest.java:42)
at utility.DataBaseConTest.main(DataBaseConTest.java:70)
Caused by: java.lang.ClassCastException: org.apache.commons.dbcp.BasicDataSourceFactory cannot be cast to javax.naming.spi.InitialContextFactory
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)



I did following coding in my application










auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
factory="oracle.jdbc.pool.OracleDataSourceFactory"
url="jdbc:oracle:thin:@172.17.89.158:1521:trdxdemo"
user="npex_app_1"
password="npex_app_1"
maxActive="20"
maxIdle="10"
maxWait="-1" />








Oracle Database connection pooling
jdbc/trdxdemo
javax.sql.DataSource
Container



and this is my java file




Hashtable env= new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"org.apache.commons.dbcp.BasicDataSourceFactory");
Context initContext = null;
OracleDataSource ds = null;
Connection con=null;

try {
System.out.println("Just the beginning :");
initContext = new InitialContext(env);
System.out.println("After Initial Context :");
Context envContext = (Context) initContext.lookup("jdbc/trdxdemo");
System.out.println("After try, details are :");
ds = (OracleDataSource) envContext.lookup("jdbc/trdxdemo");

if (envContext == null) throw new Exception("Error: No Context");
if (ds == null) throw new Exception("Error: No DataSource");
if (ds != null) con = ds.getConnection();

System.out.print("Connection details are :"+con.toString());
} catch (Exception ne) {
ne.printStackTrace();
}





when I don't put "INITIAL_CONTEXT_FACTORY" in the java file, I get below error




javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at utility.DataBaseConTest.callDatabase(DataBaseConTest.java:44)
at utility.DataBaseConTest.main(DataBaseConTest.java:70)

   <<Less
About | Sitemap | Contact