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>