my dog learned polymorphism
The moose likes Tomcat and the fly likes getting javax.naming.NameNotFound Exception. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "getting javax.naming.NameNotFound Exception." Watch "getting javax.naming.NameNotFound Exception." New topic

getting javax.naming.NameNotFound Exception.

Suchitra Bhat
Ranch Hand

Joined: Dec 30, 2005
Posts: 62
HI All,

How do i set the JNDI Data source name in tomcat?

my System DSN name is "someDSN" and my code to return the Datasource is as below(,

private String dsName=null;

public DSLogin(String dsName){
public DataSource getDataSource() {

try {

Context ctx = new InitialContext();
dataSource = (DataSource) ctx.lookup("java:comp/env/"+dsName);
catch (NamingException ex) {
System.out.println("DataSource: ");ex.printStackTrace();
return dataSource;

I am calling the above method as follows,
DataSource dataSource = new DataSource("someDSN");

I am getting javax.naming.NameNotFound Exception.

Any pointers will be helpful.

Murad Iqbal
Ranch Hand

Joined: Dec 09, 2003
Posts: 90
Hi Such,

What driver are you using? Is it jdbcodbdriver? Try doing it like this and update us if you find any luck:

javax.naming.Context ctx= new javax.naming.InitialContext( );
javax.sql.DataSource ds = ctx.lookup("java:comp/env/jdbc/"+dsn);
java.sql.Connection conn = ds.getConnection( );

I agree. Here's the link:
subject: getting javax.naming.NameNotFound Exception.
It's not a secret anymore!