glenn 01/03/04 10:57:10 Added: jdbc/examples/web jndijdbc.jsp Log: Add support for JNDI named JDBC DataSource, contributed by Rich Catlett. Revision Changes Path 1.1 jakarta-taglibs/jdbc/examples/web/jndijdbc.jsp Index: jndijdbc.jsp =================================================================== <%@ taglib uri="http://jakarta.apache.org/taglibs/jdbc" prefix="sql" %> <P><B>Opening connection</B></P> <sql:connection id="conn1"> <sql:jndiname><%=request.getParameter("jndiname")%></sql:jndiname> </sql:connection> <P><B>Connection is closed?</B></P> <jsp:getProperty name="conn1" property="closed"/> <P><B>Deleteing the results of the last test</B></P> <sql:statement id="stmt1" conn="conn1"> <sql:query>delete from test_books where id > 2</sql:query> <sql:execute/> </sql:statement> <P><B>Showing current contents of the "test_books" table</B></P> <table> <tr><th>id</th><th>name</th><th>description</th></tr> <sql:preparedStatement id="stmt2" conn="conn1"> <sql:query> select id, name, description from test_books order by 1 </sql:query> <sql:resultSet id="rset1"> <tr> <td><sql:getColumn position="1"/></td> <td><sql:getColumn position="2"/></td> <td><sql:getColumn position="3"/><sql:wasNull>[no description]</sql:wasNull></td> </tr> </sql:resultSet> </sql:preparedStatement> </table> <P><B>Inseting a row using the "statement" tag</B></P> <sql:statement id="stmt3" conn="conn1"> <sql:query> insert into test_books (id, name) values (3, '<sql:escapeSql>Gravity's Rainbow</sql:escapeSql>') </sql:query> <sql:execute/> </sql:statement> <P><B>Showing current contents of the "test_books" table</B></P> <table> <tr><th>id</th><th>name</th><th>description</th></tr> <sql:preparedStatement id="stmt4" conn="conn1"> <sql:query> select id, name, description from test_books order by 1 </sql:query> <sql:resultSet id="rset2"> <tr> <td><sql:getColumn position="1"/></td> <td><sql:getColumn position="2"/></td> <td><sql:getColumn position="3"/><sql:wasNull>[no description]</sql:wasNull></td> </tr> </sql:resultSet> </sql:preparedStatement> </table> <P><B>Selecting back the title of book 3, assigning the value to an attribute</B></P> <sql:preparedStatement id="stmt5" conn="conn1"> <sql:query> select name from test_books where id = 3 order by 1 </sql:query> <sql:resultSet id="rset3"> <sql:getColumn position="1" to="bookName"/> </sql:resultSet> </sql:preparedStatement> <P><B>Inserting that title into a new row with a "preparedStatement" tag, adding a description</B></P> <sql:preparedStatement id="stmt6" conn="conn1"> <sql:query> insert into test_books (id, name, description) values (?, ?, ?) </sql:query> <sql:execute> The contents of an execute body are not included in the output <sql:setColumn position="1">4</sql:setColumn> <sql:setColumn position="2"><%=pageContext.getAttribute("bookName")%></sql:setColumn> <sql:setColumn position="3">book by Pynchon</sql:setColumn> </sql:execute> </sql:preparedStatement> <P><B>Showing current contents of the "test_books" table</B></P> <table> <tr><th>id</th><th>name</th><th>description</th></tr> <sql:preparedStatement id="stmt6" conn="conn1"> <sql:query> select id, name, description from test_books order by 1 </sql:query> <sql:resultSet id="rset4"> <tr> <td><sql:getColumn position="1"/></td> <td><sql:getColumn position="2"/></td> <td><sql:getColumn position="3" to="description"/> <sql:wasNotNull>Description: <%= pageContext.getAttribute("description") %></sql:wasNotNull> <sql:wasNull>[no description]</sql:wasNull></td> </tr> </sql:resultSet> </sql:preparedStatement> </table> <p><b>For fun, pretend that the ids are British money</b></p> <table> <sql:preparedStatement id="stmt7" conn="conn1"> <sql:query> select id from test_books order by 1 </sql:query> <sql:resultSet id="rset5"> <tr> <td><sql:getNumber colName="id" format="CURRENCY" locale="en_GB"/></td> </tr> </sql:resultSet> </sql:preparedStatement> </table> <P><B>Closing the database connection</B></P> <sql:closeConnection conn="conn1"/> <P><B>Connection is closed?</B></P> <jsp:getProperty name="conn1" property="closed"/> <p><b>Success!</b></p>
