Announcement Announcement Module
Collapse
No announcement yet.
JSTL/SQL and Spring's datasource Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JSTL/SQL and Spring's datasource

    Hello,
    I want to use the sql-Tag (JSTL) and wonder how I could use the datasource, which is instantiated by Spring as usual (org.springframework.jdbc.datasource.DriverManager DataSource bean).

    How do I get JSTL to use this datasource? I think <sql:setDataSource> accepts only JNDI names...

    Thanks
    Chris

  • #2
    While I'd try and avoid using the SQL tags if possible; you can probably use the org.springframework.jndi.JndiTemplate class to bind the dataSource to a JNDI name so that the tags can access it.

    Comment


    • #3
      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)

      Comment

      Working...
      X