Connecting a Tomcat datasource to Teiid

Solution Verified - Updated -

Environment

JBoss Enterprise Data Services Platform

5.2/5.3

Issue

How can we configure a Tomcat datasource to use Teiid.

Resolution

The following example uses the Portfolio VDB from the "eds_multi_source_federation" quickstart example.

context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/TomcatTeiidExample">
<Resource auth="Container" 
           driverClassName="org.teiid.jdbc.TeiidDriver" 
           maxActive="100" 
           maxIdle="30" 
           maxWait="10000" 
           name="jdbc/TestDB" 
           password="user" 
           type="javax.sql.DataSource" 
           url="jdbc:teiid:Portfolio@mm://localhost:31000" 
           username="user"/>
</Context>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
      <resource-ref>
      <description>DB Connection</description>
      <res-ref-name>jdbc/TestDB</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
  </resource-ref>
</web-app>

jsp:

<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>



  <html>
  <head>

    <sql:query var="Stock" dataSource="jdbc/TestDB">
       select * from Stock
    </sql:query>

  </head>
  <body>
    <h1>JDBC JNDI Resource Test</h1>
    <table width='600' border='1'>

      <c:forEach var="Stock" items="${Stock.rows}">
        <tr>
           <td> ${Stock.symbol}</td>
           <td> ${Stock.price} </td>
        </tr>
      </c:forEach>
    </table>
  </body>
  </html>

You will also need to make sure that teiid-client.jar is in the classpath.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.