1 Reply Latest reply on Dec 2, 2002 2:21 PM by ray

    jsp jstl dataSource

    ray Newbie

      Hi,
      I have a datasource accessable from jsp pages through scriplets
      <%
      dataSource ds = initialContext...
      %>
      it works.


      but when I try to use the same dataSource for a jstl tags

      <sql:query datasource="${ds}">
      jetty says datasource='null'

      any ideas?
      Regards
      Ray

        • 1. Re: jsp jstl dataSource
          ray Newbie


          JSP Page


          <%
          String browserOutput=" " ;

          Connection con;
          ResultSet rs=null;
          javax.sql.DataSource dataSource = null;
          try {
          Context context = new InitialContext();
          dataSource = (javax.sql.DataSource)context.lookup("java:/MSSQLDS");


          } catch ( NamingException e ) {
          System.err.print( "NamingException: Cannot connect to MSSQLDS" );
          System.err.println( e.getMessage() );

          }

          try {
          con = dataSource.getConnection();
          PreparedStatement stmt =con.prepareStatement("SELECT * FROM dbo.ADLT_ED_O20_ENRL");
          // stmt.setString(1, userId);

          rs= stmt.executeQuery();
          if (rs.next()) {

          browserOutput= rs.getString(1) +","+ rs.getString(2) +","+ rs.getString(3) ;

          }
          else{
          browserOutput="cannot connect to ms sql server";
          }
          //stmt.close();
          //con.close();

          } catch(SQLException ex) {
          System.err.println("SQLException: " + ex.getMessage());
          }


          %>
          <%=browserOutput%><!--this line woks, the lines below dont-->

          <sql:query var="rs" dataSource="${dataSource}">
          SELECT * FROM dbo.ADLT_ED_O20_ENRL
          </sql:query>
          <c:forEach items="${rs.rows}" var="row">
          <c:out value="${row.ACT_FG}"/>
          </c:forEach>