I tried your suggestion of using JndiTemplate, as well as just using a new InitialContext - but it doesn't work. Here's my code in a ServletContextListener:
Code:
// bind the dataSource bean to JNDI
String jndiName = "jdbc/" + context.getServletContextName();
try {
JndiTemplate jndiTemplate = new JndiTemplate();
log.debug("Binding dataSource to '" + jndiName + "'");
jndiTemplate.bind(jndiName, ctx.getBean("dataSource"));
} catch (NamingException ne) {
log.warn(ne.getMessage());
}
When I try to load a JSP with JSTL's SQL Tags, I get:
Code:
javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "No suitable driver"
at org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.getConnection(QueryTagSupport.java:276)
at org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doStartTag(QueryTagSupport.java:159)
at org.apache.taglibs.standard.tag.el.sql.QueryTag.doStartTag(QueryTag.java:85)
at org.apache.jsp.demos.users_jsp._jspx_meth_sql_query_0(org.apache.jsp.demos.users_jsp:382)
at org.apache.jsp.demos.users_jsp._jspService(org.apache.jsp.demos.users_jsp:161)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)