I put the code in Init in a servlet, I put the following in web.xml file
<servlet>
<servlet-name>ApplStartup</servlet-name>
<servlet-class>
com.odps.eta.servlets.ApplStartServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
I started
Tomcat , but i don't see the msg that gets printed in init() method. Is this the correct way.
public class ApplStartServlet {
Map codesData = new HashMap();
public void init(ServletConfig config) throws ServletException {
try{
getCodes();
System.out.println("in Init");
}catch (Exception e) {
}
}
public void getCodes()throws Exception
{
Connection conn= null;
try{
conn= ETAConnectionPool.getInstance().getConnection();
OracleCallableStatement cs=null;
ResultSet rs=null;
cs = (OracleCallableStatement) conn
.prepareCall("{call CODES(?)}");
cs.registerOutParameter (1, OracleTypes.CURSOR);
cs.executeQuery();
rs = cs.getCursor(1);
codesData = new HashMap();
while (rs.next())
{
String codeValue=rs.getString("VALUE");
String codeMeaning=rs.getString("MEANING");
codesData.put(codeValue,codeMeaning);
}
} catch (Exception e) {
throw new Exception(e.toString());
}
finally{
try{
conn.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
public String getMeaning(String value)
{
String meaning=(String)codesData.get(value);
System.out.println("Meaning "+meaning);
return meaning;
}
}