I have a Datasource created in Weblogic but when I invoke it from a class, it generates the error:
javax.naming.NamingException: Lookup failed for 'jdbc / ConexionFV' in SerialContext [myEnv = {java.naming.provider.url = t3: //127.0.0.1: 7001, java.naming.factory.initial = weblogic.jndi.WLInitialContextFactory, java.naming.factory.state = com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs = com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: ConexionFV not found]
If someone can guide me to understand what I am doing wrong, I would greatly appreciate the help ... this is my code.
private static InitialContext ctx = null;
//public static InitialContext getInitialContext( ) throws NamingException {
public static synchronized Connection getConexion() {
Context ctx = null;
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://127.0.0.1:7001");//hostname:port");
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
ctx = new InitialContext(ht);
javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup ("jdbc/ConexionFV");
conn = ds.getConnection();
}catch (Exception e) {
System.out.println("Error --> " + e);
conn = null;
}
return conn;
}