<%@ page import="java.io.*,java.util.*,java.sql.*"%> <%@ page import="javax.servlet.http.*,javax.servlet.*"%> <%@ page import="java.util.Date,java.text.*" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%> <html> <head> <title>JSTL sql:transaction Tag</title> </head> <body> <sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/TEST" user="root" password="cohondob"/> <% Date DoB = new Date("2013/10/23"); int studentId = 1111; %> <sql:transaction dataSource="${snapshot}"> <sql:update var="count"> UPDATE Students SET firstName = 'Sandhya' WHERE Id = 2222 </sql:update> <sql:update var="count"> UPDATE Students SET fistName = 'Sweetu' WHERE Id = 3333 </sql:update> <sql:update var="count"> INSERT INTO Students VALUES (4444,'Neha', 'Verma', '2013/10/23'); </sql:update> </sql:transaction> <sql:query dataSource="${snapshot}" var="result"> SELECT * from Students; </sql:query> <table border="1" width="100%"> <tr> <th>Emp ID</th> <th>First Name</th> <th>Last Name</th> <th>DoB</th> </tr> <c:forEach var="row" items="${result.rows}"> <tr> <td><c:out value="${row.id}"/></td> <td><c:out value="${row.first}"/></td> <td><c:out value="${row.last}"/></td> <td><c:out value="${row.dob}"/></td> </tr> </c:forEach> </table> </body> </html>
Emp ID | First Name | Last Name | DOB |
---|---|---|---|
1111 | Dinesh | Rajput | 2013/10/23 |
2222 | Anu | Rajput | 2013/10/23 |
2222 | Sweetu | Rajput | 2013/10/23 |
2222 | Sandhya | Bansal | 2013/10/23 |
Labels: JSTL