1. Open Context.xml file, which is located under tomcat/conf/context.xml
2. Add Following Resource configuration under
3. Open your applications web.xml file and add resource-reference in that.
4. Look at the following code to lookup JNDI
private static InitialContext ctx = null;
private static DataSource ds = null;
try
{
ctx = new InitialContext();
ds = (DataSource)ctx.lookup("java:comp/env/jdbc/test");
if(ds != null){
log.info("DbUtils: datasource setup successfully.");
}
}catch (Exception e)
{
System.out.println("Error is .. "+e.getMessage());
}
5. Finally, deploy your application and use it.