error connecting to a Datasource in weblogic

2

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;
}
    
asked by Mckimley 10.10.2016 в 19:04
source

2 answers

1

Try changing the name Datasource to something other than jndi. That is, if your jndi is "jdbc / ConexionFV", the Datasource should be different to ConexionFV, for example if it is a DB2 the DB, DB2conexionFV with jndi "jdbc / ConexinoFV".

    
answered by 10.01.2017 в 15:53
0

Regularly this 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 ]

is caused because there is an error writing the correct name of the Data Source or it is not specified.

Check in your file weblogic.properties the name of the Data Source, apparently ConexionFV is not correct :

 javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup ("jdbc/ConexionFV");
    
answered by 10.10.2016 в 19:58