wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android 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(DataSource.java),

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: http://aspose.com/file-tools
subject: getting javax.naming.NameNotFound Exception.
Similar Threads
database-access JavaBean - thread safety
Cactus EJB(MDB) Issue
Using DataSource with Oracle 10g Application Server results in error
Problem occurs when using DataSource connection in WSAD
Encrypting login id and Password in .xml file