Results 1 to 3 of 3

Thread: JSTL/SQL and Spring's datasource

  1. #1
    Join Date
    Oct 2004
    Posts
    14

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Auburn, AL, USA.
    Posts
    106

    Default

    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.

  3. #3
    Join Date
    Aug 2004
    Location
    Denver
    Posts
    249

    Default

    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)

Similar Threads

  1. Two SessionFactories using the same DataSource
    By Joris Kuipers in forum Data
    Replies: 4
    Last Post: Sep 12th, 2005, 02:57 AM
  2. Replies: 3
    Last Post: Jun 16th, 2005, 09:32 PM
  3. Replies: 4
    Last Post: Apr 20th, 2005, 10:43 AM
  4. Replies: 1
    Last Post: Jan 15th, 2005, 01:11 PM
  5. Help datasource not defined
    By jlm in forum Data
    Replies: 4
    Last Post: Aug 16th, 2004, 05:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •