Bug 8317

Summary: sql:setDataSource is not working correctly with javax.servlet.jsp.jstl.sql.dataSource
Product: Taglibs Reporter: Lance Andersen <Lance.Andersen>
Component: Standard TaglibAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: major CC: Ryan.Lubke
Priority: P3    
Version: 1.0   
Target Milestone: ---   
Hardware: All   
OS: All   

Description Lance Andersen 2002-04-19 22:36:43 UTC
<sql:setDataSource dataSource="${jstlDS}"  />  and it's RT cousin  do not work
correctly when passed a DataSource or a list of DriverManager parameters...



<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
<%@ taglib prefix="sql_rt" uri="http://java.sun.com/jstl/sql_rt" %>
<%@ taglib prefix="tck" uri="http://java.sun.com/jstltck/jstltck-util" %>
<%@ page import="javax.sql.*, java.util.*" %>

<tck:test testName="positiveSetDataSourceQueryNoVarAttributeDataSourceTest">

  <!-- EL: Validate sql:query and sql:setDataSource actions by specifying a 
        DataSource Object for javax.servlet.jsp.jstl.sql.dataSource-->

   <h1>Validate sql:query and sql:setDataSource actions by specifying a
       DataSource object for javax.servlet.jsp.jstl.sql.dataSource using EL</h1>
   <p>

  <c:catch var="ex"  >
      <sql:setDataSource dataSource="${jstlDS}"  />  
  </c:catch>

   <c:choose>
      <c:when test="${!empty ex}">
         <H2>ERROR:</H2>
         Could not create a dataSource using  a <strong>DataSource Object
         </strong> for javax.servlet.jsp.jstl.sql.dataSource! The Exception that
         was raised is: <strong><c:out value='${ex}' escapeXml='false'
/></strong>.
         <p>
      </c:when>
      <c:otherwise>
         Successfully created a DataSource.
         <p>
      </c:otherwise>
   </c:choose>
 

  <c:catch var="ex2"  >
      <sql:query var='resultSet'>        
         <c:out value="${sqlProps.Simple_Select_Query}" />  
      </sql:query>
   </c:catch>

   <c:choose>
      <c:when test="${!empty ex2}">
         <H2>ERROR:</H2>
         Could not execute the query <strong><c:out
value="${sqlProps.Simple_Select_Query}" />
         </strong> when using  a <strong>DataSource Object </strong> for 
          javax.servlet.jsp.jstl.sql.dataSource! The Exception that was raised
is: 
         <strong><c:out value='${ex2}' escapeXml='false' /></strong>.
         <p>
      </c:when>
      <c:otherwise>
         Successfully executed the query when
javax.servlet.jsp.jstl.sql.dataSource 
         was provided a DataSource Object.
         <p>
      </c:otherwise>
   </c:choose>
 

   <!-- RT: Validate sql:query and sql:setDataSource actions by specifying a 
        DataSource Object for javax.servlet.jsp.jstl.sql.dataSource-->

   <h1>Validate sql:query and sql:setDataSource actions by specifying a
       DataSource object for javax.servlet.jsp.jstl.sql.dataSource using RT</h1>
   <p>
 <c:catch var="ex3"  >
      <sql_rt:setDataSource 
          dataSource='<%=(DataSource) pageContext.getAttribute("jstlDS",
PageContext.APPLICATION_SCOPE) %>'
          /> 
  </c:catch>

   <c:choose>
      <c:when test="${!empty ex3}">
         <H2>ERROR:</H2>
         Could not create a dataSource using  a <strong>DataSource Object
         </strong> for javax.servlet.jsp.jstl.sql.dataSource! The Exception that 
         was raised is: <strong><c:out value='${ex3}'  escapeXml='false'
/></strong>.
         <p>
      </c:when>
      <c:otherwise>
         Successfully created a DataSource.
         <p>
      </c:otherwise>
   </c:choose>
 

  <c:catch var="ex4"  >
    <sql_rt:query var="resultSet2" >
                 
         <c:out value="${sqlProps.Simple_Select_Query}" /> 
      </sql_rt:query>
      
   </c:catch>

   <c:choose>
      <c:when test="${!empty ex4}">
         <H2>ERROR:</H2>
         Could not execute the query <strong><c:out
value="${sqlProps.Simple_Select_Query}" />
         </strong> when using  a<strong>DataSource Object</strong> for
         javax.servlet.jsp.jstl.sql.dataSource! The Exception that was raised
is: 
         <strong><c:out value='${ex2}' escapeXml='false' /></strong>.         
         <p>
      </c:when>
      <c:otherwise>
         Successfully executed the query when
javax.servlet.jsp.jstl.sql.dataSource  
         was provided a DataSource Object.  
         <p>
      </c:otherwise>
   </c:choose>
 
</tck:test>
Comment 1 Jan Luehe 2002-04-22 21:50:10 UTC
<sql:setDataSource> was setting the javax.servlet.jsp.jstl.sql.dataSource
configuration variable using pageContext.setAttribute() instead of Config.set().