Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting javax.naming.NameNotFound Exception.

 
Suchitra Bhat
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
 
Murad Iqbal
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic