SqlJstlTest.jsp.jsp
Dosyayı İndir
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<html>
<body>
<sql:setDataSource var="myDatasource"
url="jdbc:derby://localhost:1527/sample" user="app" password="app"/>
<sql:query var="customersResult" dataSource="${myDatasource}"
sql="select * from Customer"/>
<table>
<tr>
<th>Customer ID</th>
<th>Name</th>
<th>Phone</th>
<th>Email</th>
</tr>
<c:forEach var="row" items="${customersResult.rows}">
<tr>
<td><c:out value="${row.customer_id}"/></td>
<td><c:out value="${row.name}"/></td>
<td><c:out value="${row.phone}"/></td>
<td><c:out value="${row.email}"/></td>
</tr>
</c:forEach>
</table>
<c:set var="customerId" value="106"/>
<sql:query var="customerResult" dataSource="${myDatasource}"
sql="select * from Customer where customer_id=?">
<sql:param value="${customerId}"/>
</sql:query>
<c:set var="customerRow" value="${customerResult.rows[0]}"/>
<b>Customer : <c:out value="${customerId}"/></b><br/>
<table>
<tr>
<td>Name</td><td>:</td>
<td><c:out value="${customerResult.rows[0].name}"/></td>
</tr>
<tr>
<td>Phone</td><td>:</td>
<td><c:out value="${customerRow.phone}"/></td>
</tr>
<tr>
<td>Email</td><td>:</td>
<td><c:out value="${customerRow.email}"/></td>
</tr>
</table>
<c:set var="myOrderNum" value="654321"/>
<c:set var="myCustomerId" value="106"/>
<c:set var="myProductId" value="980001"/>
<c:set var="myQuantity" value="5"/>
<c:set var="mySalesDate" value="1.1.2008"/>
<sql:update dataSource="${myDatasource}">
insert into
purchase_order(order_num,customer_id,product_id,quantity,sales_date)
values(?,?,?,?,?)
<sql:param value="${myOrderNum}"/>
<sql:param value="${myCustomerId}"/>
<sql:param value="${myProductId}"/>
<sql:param value="${myQuantity}"/>
<sql:param value="${mySalesDate}"/>
</sql:update>
</body>
</html>
Dosyayı İndir