Docstoc
EXCLUSIVE OFFER FOR DOCSTOC USERS
Try the all-new QuickBooks Online for FREE.  No credit card required.

How to select and insert data in Mysql database using JSP

Document Sample
How to select and insert data in Mysql database using JSP Powered By Docstoc
					<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql"%>
<html>
<sql:setDataSource var="dataSource" driver="com.mysql.jdbc.Driver"
      url="jdbc:mysql://localhost:3306/jstlcomment" user="root"
password=""
      scope="session" />
      <body>
      <div style="margin-left:220px;">
      <h1> <span style="color: cyan;margin-left:150px">Comment Arena
<span></h1>
<span style="font-family: Arial, Helvetica, sans-serif;"><b>What's
up?</b></span><br />
<form method="post" style="margin: 0px; padding: 0px;">
Name: <input type="name" name="name" required><br><br>
<textarea cols="30" id="update" maxlength="200" name="post" rows="3"
style="border-color: rgb(51, 51, 51); font-size: 12px; margin: 0px;
padding-left: 0px; padding-top: 0px; width: 550px;"
required></textarea><br style="margin: 0px; padding: 0px;" />
<br />
<input class="update_button" id="update_button" style="margin: 0px;
padding: 0px;" type="submit" value=" Publish Comment " /><br /></form>
<c:if test="${pageContext.request.method=='POST'}">
      <c:catch var="exception">
            <sql:update dataSource="${dataSource}" var="updatedTable">
    INSERT INTO comment (post,name) VALUES (?,?)
    <sql:param value="${param.post}" />
      <sql:param value="${param.name}" />
            </sql:update>
            </c:catch>
      <c:if test="${exception!=null}">
            <b>Exception : </b>
            <c:out value="${exception}" />
      </c:if>
</c:if>
<c:if test="${pageContext.request.method=='POST'}">
<sql:query var="pt" dataSource="${dataSource}" >
SELECT * FROM comment
</sql:query>
<c:forEach var="row" items="${pt.rows}">
<br />
<b><span style="color: #38761d;">----------------------------------------
-------------------------------------------------------------------------
-----</span></b><br />
<b><c:out value="${row.name}"/> says :</b><br />
<c:out value="${row.post}"/><br />
<b><span style="color: red;">--------------------------------------------
-------------------------------------------------------------------------
-</span></b>

</c:forEach>
</c:if>
</div>
</div>
</body>
</html>

				
DOCUMENT INFO
Shared By:
Tags:
Stats:
views:42
posted:11/11/2012
language:French
pages:2
Description: Now i'll teach you How to select and insert data in Mysql database using JSP (JSTL) with interesting stuff. How to Make Facebook like Comment Using JSP