You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Al <re...@hotmail.com> on 2016/05/18 20:25:30 UTC

javax.naming.NameNotFoundException Tomcat 8.0.32









Environment:Tomcat  8.0.32
Windows 10
Eclipse Mars 2 Release 4.5.2
MySQL-connector-java-5.1.39-bin.jar
 
I'm try to set up a jndi for a MySQL database connection in eclipse using Tomcat 8.0.32 . I keep receiving the following message when I try to run code example. 
 
javax.naming.NameNotFoundException: Name [308tubeOracle] is not bound in this Context. Unable to find [308tubeOracle].
 
I believe I have set everything up correctly and would really appreciate some direction.
I have added the following two entries into the context.xml under the Tomcat Server config in Eclipse.
 <Resource     name="jdbc/308tubeOracle"     auth="Container"     type="javax.sql.DataSource"     maxActive="100"      maxIdle="30"       maxWait="10000"      driverClassName="com.mysql.jdbc.Driver"      url="jdbc:mysql://localhost:3306/testdatabase"     username="mysqladmin"      password="mypassword"      />

<ResourceLink name="jdbc/308tubeOracle"
global="jdbc/308tubeOracle"

type="javax.sql.DataSource"/>
 
I have added the following to the application web.xml in the WEB-INF folder of my application.  
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">

<display-name>com.youtube.rest</display-name>
<welcome-file-list>

<welcome-file>readme.html</welcome-file>

<welcome-file>index.html</welcome-file>

</welcome-file-list>

<resource-ref>

<description>DB Connection</description>

<!--    <res-ref-name>jdbc/tubeOracle</res-ref-name> -->

<res-ref-name>jdbc/308tubeOracle</res-ref-name>

<res-type>javax.sql.DataSource</res-type>

<res-auth>Container</res-auth>

</resource-ref>
 I have copied the MySQL-connector-java-5.1.39-bin.jar to the  WEB-INF \lib in my application . 
Here is the code I call the context with to try and get the DataSource. I added the while loop to try to
  figure out what was going on.  It does print the name 308tubeOracle at that point. But I still get theName [308tubeOracle] is not bound in this Context. Unable to find [308tubeOracle].
 
import javax.naming.*;import javax.sql.*; public class get {private static DataSource Oracle308tube = null;
private static Context context = null; 
public static DataSource Oracle308tubeConn() throws Exception {if(Oracle308tube != null){

return Oracle308tube;
}try {			    if (context == null){
context = new InitialContext();
}    NamingEnumeration<NameClassPair> list = context.list("java:comp/env/jdbc");			while (list.hasMore()) {			  System.out.println(list.next().getName());}Oracle308tube = (DataSource) context.lookup("308tubeOracle");}catch (Exception e){		e.printStackTrace(); 	}return Oracle308tube;}} 
 
 
 
 



 		 	   		  

RE: AW: javax.naming.NameNotFoundException Tomcat 8.0.32

Posted by Al <re...@hotmail.com>.
Thanks  for the reply, that did not work but the following did. If some one could explain why I needed to do it this way it would be much appreciated.
 
This did not work :Oracle308tube = context.lookup("jdbc/308tubeOracle");      This worked:       Context envContext  = (Context)context.lookup("java:/comp/env");            Oracle308tube = (DataSource)envContext.lookup("jdbc/308tubeOracle");             
 
> From: sebastian.trost@dms-ag.ch
> To: users@tomcat.apache.org
> Subject: AW: javax.naming.NameNotFoundException Tomcat 8.0.32
> Date: Thu, 19 May 2016 12:04:50 +0000
> 
> Hi Al,
> 
> Try using context.lookup("jdbc/308tubeOracle") instead of context.lookup("308tubeOracle").
> 
> Regards
> Sebastian
> 
> -----Ursprüngliche Nachricht-----
> Von: Al [mailto:rebrabla@hotmail.com] 
> Gesendet: Mittwoch, 18. Mai 2016 22:26
> An: users@tomcat.apache.org
> Betreff: javax.naming.NameNotFoundException Tomcat 8.0.32
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Environment:Tomcat  8.0.32
> Windows 10
> Eclipse Mars 2 Release 4.5.2
> MySQL-connector-java-5.1.39-bin.jar
>  
> I'm try to set up a jndi for a MySQL database connection in eclipse using Tomcat 8.0.32 . I keep receiving the following message when I try to run code example. 
>  
> javax.naming.NameNotFoundException: Name [308tubeOracle] is not bound in this Context. Unable to find [308tubeOracle].
>  
> I believe I have set everything up correctly and would really appreciate some direction.
> I have added the following two entries into the context.xml under the Tomcat Server config in Eclipse.
>  <Resource     name="jdbc/308tubeOracle"     auth="Container"     type="javax.sql.DataSource"     maxActive="100"      maxIdle="30"       maxWait="10000"      driverClassName="com.mysql.jdbc.Driver"      url="jdbc:mysql://localhost:3306/testdatabase"     username="mysqladmin"      password="mypassword"      />
> 
> <ResourceLink name="jdbc/308tubeOracle"
> global="jdbc/308tubeOracle"
> 
> type="javax.sql.DataSource"/>
>  
> I have added the following to the application web.xml in the WEB-INF folder of my application.  
> <?xml version="1.0" encoding="UTF-8"?>
> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
> 
> <display-name>com.youtube.rest</display-name>
> <welcome-file-list>
> 
> <welcome-file>readme.html</welcome-file>
> 
> <welcome-file>index.html</welcome-file>
> 
> </welcome-file-list>
> 
> <resource-ref>
> 
> <description>DB Connection</description>
> 
> <!--    <res-ref-name>jdbc/tubeOracle</res-ref-name> -->
> 
> <res-ref-name>jdbc/308tubeOracle</res-ref-name>
> 
> <res-type>javax.sql.DataSource</res-type>
> 
> <res-auth>Container</res-auth>
> 
> </resource-ref>
>  I have copied the MySQL-connector-java-5.1.39-bin.jar to the  WEB-INF \lib in my application . 
> Here is the code I call the context with to try and get the DataSource. I added the while loop to try to
>   figure out what was going on.  It does print the name 308tubeOracle at that point. But I still get theName [308tubeOracle] is not bound in this Context. Unable to find [308tubeOracle].
>  
> import javax.naming.*;import javax.sql.*; public class get {private static DataSource Oracle308tube = null;
> private static Context context = null; 
> public static DataSource Oracle308tubeConn() throws Exception {if(Oracle308tube != null){
> 
> return Oracle308tube;
> }try {			    if (context == null){
> context = new InitialContext();
> }    NamingEnumeration<NameClassPair> list = context.list("java:comp/env/jdbc");			while (list.hasMore()) {			  System.out.println(list.next().getName());}Oracle308tube = (DataSource) context.lookup("308tubeOracle");}catch (Exception e){		e.printStackTrace(); 	}return Oracle308tube;}} 
>  
>  
>  
>  
> 
> 
> 
>  		 	   		  
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
 		 	   		  

AW: javax.naming.NameNotFoundException Tomcat 8.0.32

Posted by Sebastian Trost <se...@dms-ag.ch>.
Hi Al,

Try using context.lookup("jdbc/308tubeOracle") instead of context.lookup("308tubeOracle").

Regards
Sebastian

-----Ursprüngliche Nachricht-----
Von: Al [mailto:rebrabla@hotmail.com] 
Gesendet: Mittwoch, 18. Mai 2016 22:26
An: users@tomcat.apache.org
Betreff: javax.naming.NameNotFoundException Tomcat 8.0.32










Environment:Tomcat  8.0.32
Windows 10
Eclipse Mars 2 Release 4.5.2
MySQL-connector-java-5.1.39-bin.jar
 
I'm try to set up a jndi for a MySQL database connection in eclipse using Tomcat 8.0.32 . I keep receiving the following message when I try to run code example. 
 
javax.naming.NameNotFoundException: Name [308tubeOracle] is not bound in this Context. Unable to find [308tubeOracle].
 
I believe I have set everything up correctly and would really appreciate some direction.
I have added the following two entries into the context.xml under the Tomcat Server config in Eclipse.
 <Resource     name="jdbc/308tubeOracle"     auth="Container"     type="javax.sql.DataSource"     maxActive="100"      maxIdle="30"       maxWait="10000"      driverClassName="com.mysql.jdbc.Driver"      url="jdbc:mysql://localhost:3306/testdatabase"     username="mysqladmin"      password="mypassword"      />

<ResourceLink name="jdbc/308tubeOracle"
global="jdbc/308tubeOracle"

type="javax.sql.DataSource"/>
 
I have added the following to the application web.xml in the WEB-INF folder of my application.  
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">

<display-name>com.youtube.rest</display-name>
<welcome-file-list>

<welcome-file>readme.html</welcome-file>

<welcome-file>index.html</welcome-file>

</welcome-file-list>

<resource-ref>

<description>DB Connection</description>

<!--    <res-ref-name>jdbc/tubeOracle</res-ref-name> -->

<res-ref-name>jdbc/308tubeOracle</res-ref-name>

<res-type>javax.sql.DataSource</res-type>

<res-auth>Container</res-auth>

</resource-ref>
 I have copied the MySQL-connector-java-5.1.39-bin.jar to the  WEB-INF \lib in my application . 
Here is the code I call the context with to try and get the DataSource. I added the while loop to try to
  figure out what was going on.  It does print the name 308tubeOracle at that point. But I still get theName [308tubeOracle] is not bound in this Context. Unable to find [308tubeOracle].
 
import javax.naming.*;import javax.sql.*; public class get {private static DataSource Oracle308tube = null;
private static Context context = null; 
public static DataSource Oracle308tubeConn() throws Exception {if(Oracle308tube != null){

return Oracle308tube;
}try {			    if (context == null){
context = new InitialContext();
}    NamingEnumeration<NameClassPair> list = context.list("java:comp/env/jdbc");			while (list.hasMore()) {			  System.out.println(list.next().getName());}Oracle308tube = (DataSource) context.lookup("308tubeOracle");}catch (Exception e){		e.printStackTrace(); 	}return Oracle308tube;}} 
 
 
 
 



 		 	   		  

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org