<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql"%>
<sql:setDataSource var="dataSource" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/mahendra" user="root" password="root"
scope="session" />
<html>
<head>
<title>General Query</title>
</head>
<body>
Please enter a query:
<br />
<form method="post"><textarea name="cmd" cols="40" rows="5"></textarea>
<br />
<input type="submit" /></form>
</body>
<c:if test="${pageContext.request.method=='POST'}">
<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>
<font size="4" color="green">Query : </FONT>
<u><c:out value="${str}" /></u>
<c:catch var="e">
<sql:query var="users" dataSource="${dataSource}" sql="${param.cmd}" />
<table border="1" size="100%">
<c:forEach var="row" items="${users.rows}">
<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>
</html>
|