The source of the problem could be found in the org.apache.taglibs.standard.tag.common.sql.DataSourceUtil class of the Jakarta implementation of JSTL. The problem is that the SQL function looks for the DataSource in the “java:comp/env” namespace where as my datasource was in the “java:” namespace.
The solution is to map the datasource to Tomcat using the web.xml and jboss-web.xml deployment descriptors:
web.xml
<!-- JDBC DataSources (java:comp/env/jdbc) -->
<resource-ref>
<description>The used datasource</description>
<res-ref-name>jdbc/DefaultDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
jboss-web.xml
<!-- make sure the web container can get jdbc connections -->
<resource-ref>
<res-ref-name>jdbc/DefaultDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<jndi-name>java:/pestikom2</jndi-name>
</resource-ref>
The above makes the java:/pestikom2 datasource from JBoss available in the java:/comp/env namespace in Tomcat. The datasource can now be referenced from JSTL using:
<sql:query dataSource="jdbc/DefaultDS" var="some_var" scope="page" sql="select * from foo" />