Please help.
I stuck with an error While I try to get a DataSource Object from the pool the
code is following.
package com.fl.common;
public final class ServiceLocator {
private static final String JBOSS_INITIAL_CONTEXT_FACTORY =
"org.jnp.interfaces.NamingContextFactory";
private static final String JBOSS_PROVIDER_URL = "localhost:8080";
private static final String JBOSS_URL_PKG_PREFIXES =
"org.jboss.naming:org.jnp.interfaces";
public static final String ATLAS_DATASOURCE = "java://myatlasdbpool";
private static java.util.Hashtable dataSourceCache = null;
private static ServiceLocator locator = null;
static {
System.out.println("Locator Initializing");
dataSourceCache = new java.util.Hashtable();
locator = new ServiceLocator();
}
private ServiceLocator() { }
public static ServiceLocator newInstance() {
System.out.println("Returning the Locator Object");
return locator;
}
public java.sql.Connection getDBConnection() throws
java.sql.SQLException,javax.naming.NamingException {
System.out.println("Getting Data base Connection....");
if(dataSourceCache.containsKey(ATLAS_DATASOURCE)) {
System.out.println("Trying to get Connection from
CACHE...");
System.out.println("Returning Connection Object from
cache.");
return
(java.sql.Connection)dataSourceCache.get(ATLAS_DATASOURCE);
}
System.out.println("FAILED to get Connection from CACHE");
System.out.println("Trying to create new Connection...");
java.util.Properties props = new java.util.Properties();
props.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,JBOSS_INITIAL_CONTEXT_FACTORY);
props.put(javax.naming.Context.PROVIDER_URL,JBOSS_PROVIDER_URL);
props.put(javax.naming.Context.URL_PKG_PREFIXES,
JBOSS_URL_PKG_PREFIXES );
javax.naming.InitialContext context = new
javax.naming.InitialContext(props);
Object o = context.lookup(ATLAS_DATASOURCE);
System.out.println("Object Created...");
javax.sql.DataSource dataSource = null;
dataSource =
(javax.sql.DataSource)o;//javax.rmi.PortableRemoteObject.narrow(o,javax.sql.DataSource.class);
java.sql.Connection con = dataSource.getConnection();
dataSourceCache.put(ATLAS_DATASOURCE,con);
System.out.println("Returning new Connection Object.");
return con;
}
}
ERROR -----------------------------------------------------
Locator Initializing
Returning the Locator Object
Getting Data base Connection....
FAILED to get Connection from CACHE
Trying to create new Connection...
Object Created...
java.lang.ClassCastException: org.jnp.interfaces.NamingContext
java.lang.ClassCastException: org.jnp.interfaces.NamingContext
at com.beo.atlas.common.ServiceLocator.getDBConnection(ServiceLocator.ja
va:56)
at AtlasClient.printData(AtlasClient.java:16)
at AtlasClient.main(AtlasClient.java:8)
PLEASE HELP..................
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3885136#3885136
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3885136
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user