• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

getting javax.naming.NameNotFound Exception.

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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){
this.dsName=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");
dataSource.getDataSource();


I am getting javax.naming.NameNotFound Exception.


Any pointers will be helpful.

Thanks,
Suchitra
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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( );



Cheers,
Murad.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!