Mega Code Archive

 
Categories / Java / JSTL
 

JSTL SQL Update

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jstl/core-rt" prefix="c-rt" %> <%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %> <sql:setDataSource var="dataSource" driver="org.gjt.mm.mysql.Driver" url="jdbc:mysql://localhost/forum?user=forumuser" scope="session" /> <html>   <head>     <title>General Query</title>   </head>   <body>   <c:choose>     <c:when test="${param.cmd!=null}">       <c:set var="str" value="${param.cmd}" />     </c:when>     <c:otherwise>       <c:set var="str"       value="select * from tableName" />     </c:otherwise>   </c:choose>   Please enter a query:   <br />   <form method="post">     <textarea name="cmd" cols="40" rows="5"> <c:out value="${str}" />     </textarea>     <br />     <input type="submit" />   </form>   <c:if test="${pageContext.request.method=='POST'}">     <c:catch var="e">       <sql:query var="users" dataSource="${dataSource}"       sql="${param.cmd}" />       <table border="1">         <c:forEach var="row" items="${users.rows}"         varStatus="status">           <jsp:useBean id="status"           type="javax.servlet.jsp.jstl.core.LoopTagStatus" />           <c-rt:if test="<%=status.getCount()==1%>">             <tr>               <c:forEach var="col" items="${row}">                 <th>                   <c:out value="${col.key}" />                 </th>               </c:forEach>             </tr>           </c-rt:if>           <tr>             <c:forEach var="col" items="${row}">               <td>                 <c:out value="${col.value}" />               </td>             </c:forEach>           </tr>         </c:forEach>       </table>     </c:catch>     <c:if test="${e!=null}">       <h3>Error</h3>       <c:out value="${e}" />     </c:if>   </c:if>   </body> </html>                     JSTL-SQL-Update.zip( 6,553 k)