File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Murach's Java Servlets and JSP this week in the Servlets 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( );

It is sorta covered in the JavaRanch Style Guide.
subject: getting javax.naming.NameNotFound Exception.
Similar Threads
Cactus EJB(MDB) Issue
Using DataSource with Oracle 10g Application Server results in error
database-access JavaBean - thread safety
Problem occurs when using DataSource connection in WSAD
Encrypting login id and Password in .xml file