java ee - How to access JNDI data source defined in weblogic 10.3.6 -
i have created jndi data-source using weblogic console not able access object web application. below details
in weblogic 10.3.6, have given jndi name datasource : jdbc/mydb
to db connection web application have written code in web application:
context initcontext = new initialcontext(); datasource ds = (datasource)initcontext.lookup("java:/comp/env/jdbc/mydb"); jndiconnection = ds.getconnection();
earlier using tomcat server , able db connection when configured resource details in file tomcat/conf/server.xml
, when using started using weblogic server getting below error:
cannot establish db connection jndi:java:/comp/env/jdbc/mydb while trying /comp/env/jdbc/mydb in /app/webapp/sample.war/1811641702. caused by: javax.naming.namenotfoundexception: while trying /comp/env/jdbc/mydb in /app/webapp/sample.war/1811641702.; remaining name '/comp/env/jdbc/mydb'
i have tried options mentioned in link : how lookup jndi resources on weblogic? still facing problems.
please let me know doing mistake, process of accessing jndi object.
after referring post:tomcat vs weblogic jndi lookup have modified code.
using below code in java program of web application has solved issue:
context initcontext = new initialcontext(); datasource ds = (datasource)initcontext.lookup("jdbc/mydb"); jndiconnection = ds.getconnection();
also in weblogic console have added jndi object admin server (under servers option) web application deployed.