java - JNDI lookup is not happening when we bind object in one project and look up from second -


I have two Java projects, in Test1 and Test2 Test 1 In the project I have a servlet with the following code

  Initial Consultant Initial Contex = New InitialContact (); Class.forName ("com.mysql.jdbc.Driver"); Connection Connection = DriverManager.getConnection ("jdbc: mysql: // localhost: 3306 / lntdb", "root", "root"); InitialContext.bind ("conn", connection); Response.getWriter () println ("bound to JNDI" + initialContext.lookup ("Cone")) ;. `Connection object with  

The above code is binding MYSQL database JNDI name conn , Since then, the Test2 project is trying to regain the connection object. Test 2 is also a servicelet with code below

  Initial Contex = New Initial Context (); . Response.getWriter () println (initialContext.lookup ("Java: Computer Application / env / Conne"));  

But I'm getting an exception stack trace below

javax.naming.NameNotFoundException: Name [Conn] is not bound in this context. [Conn] on unable to find org.apache.naming.NamingContext.lookup (NamingContext.java:820) org.apache.naming.NamingContext.lookup (NamingContext.java:154) org.apache.naming.NamingContext.lookup (on NamingContext.java:831) org.apache.naming.NamingContext.lookup (NamingContext.java:154) org.apache.naming.NamingContext.lookup (NamingContext.java:831) on org.apache.naming.NamingContext.lookup (on the NamingContext.java: 168) javax.naming.InitialContext.lookup (unknown source org.apache.naming.SelectorContext.lookup (SelectorContext.java:158) com.lnt.TestServlet.doGet (TestServlet.java:19) ) At javax.servlet at https://www.ttpServlet.service (HttpServlet.java:621) at javax.servlet.http.HttpServlet.service (HttpServlet.java:722) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter ( ApplicationFilterChain.java.35) at Org.apache.catalina.core.ApplicationFilterChain.doFil OrardWrapperValve.invoke (StandardWrapperValve.java) at ORG.apache.catalina.core.StandardContextValve.invoke (StandardContextValve.java:123) on org.apache.catalina.authenticator at org.apache.catalina.core.St (applicationFilterChain.java810) .222) or AuthenticatorBase.invoke (AuthenticatorBase.java:472) in the organization .apache.catalina.core.StandardHostValve.invoke (standardHostValve.java:168) org.apache.catalina.valves.ErrorReportValve.invoke at (ErrorReportValve.java: 99) org.apache.catalina.valves.AccessLogValve.invoke (AccessLogValve .java: 929) org.apache.catalina.core.StandardEngineValve.invoke (StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter. On org.apache.coyote at service (CoyoteAdapter.java 407) Http11.AbstractHttp11Processor.process (AbstractHttp11Processor.java:1002) at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process (AbstractProtocol.java; 85) org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run (JIoEndpoint. Java: 312) ent.ThreadPoolExecutor.runWorker (unknown source java.util.concurr) java.util.concurrent.ThreadPoolExecutor $ Worker.run (unknown source JavaklangkThreadkrun) (unknown source) `

but you can tell what is wrong in my code and why I am not able to recover the connection object

Here you can find a special reference Do not use BK which is common to both applications JNDI has different references for all applications, and those which are first binding in the application, is the first application that does not have any other application available for initial reference. There is a shock for reference.

You can follow the steps to learn


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -