here is for you
public void init(ServletConfig config) throws ServletException {
super.init(config);
try {
InitialContext initContext = new InitialContext();
log("- initContext");
if (initContext == null) log("BOOM - initContext null");
Context envContext = (Context)initContext.lookup("java:/comp/env");
log("- envContext");
if (envContext == null) log("BOOM - No Context");
ds = (DataSource)envContext.lookup("/jdbc/postgresql");
log("- DataSource");
if (ds != null) {
Connection conn = ds.getConnection();
log("- Connection");
if (conn != null) {
log("- Connection ok");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from photo");
if (rs.next()) {
}
conn.close();
log("- Connection close");
}
else
log("BOOM - DataSource null");
}
}catch (SQLException e) {e.printStackTrace();}
catch (NamingException e){e.printStackTrace();}
getServletContext().setAttribute("postgresqlDataSource", ds); // this help you
}
Georges
Gustavo Cebrian wrote:
Should I store my pool connection class in the servlet context?
Where should I create it?
I do not know a common place to execute for all the servlets so they can share resources. Is the context the only place.
Thanks.
Gustavo.
*********************************************** Gustavo Cebrian Analyst/Programmer
Want to improve the ROI on your EAI project?
Download RV Tester and reduce your development and testing timescales by as much as 50%. http://www.greenhatconsulting.com/rvtester
Green Hat Consulting Ltd. 107 Fleet Street, London EC4A 2AB DDI +44 (0)20 7936 9495 Mobile +44 (0)7788 922291 http://www.greenhatconsulting.com [EMAIL PROTECTED] ***********************************************
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]