Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ 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>JINSERT Operation</title>
</head>
<body>
 <form id="form1" name="form1" method="post" action=""><fieldset>

<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/dmd" user="root" password="root"/>
<sql:query dataSource="${snapshot}" var="result">
 SELECT * from company;
 </sql:query>

    <p>Company Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:
    <select name="companyName">
         <option>
       <c:forEach items="${result.rows}" var="row">
       <option value="${row.companyName}"><c:out value="${row.companyName}"/></option>
       </c:forEach>
          </option>

        </select>
        <p>&nbsp;</p>
     <sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/dmd" user="root" password="root"/>
<sql:query dataSource="${snapshot}" var="result">
 SELECT * from employee;
 </sql:query>

    <p>Employee Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:
    <select name="employeeName">
         <option>
       <c:forEach items="${result.rows}" var="row">
       <option value="${row.empName}"><c:out value="${row.empName}"/></option>
       </c:forEach>
          </option>

        </select>
        <p>&nbsp;</p>

    <p>Team Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:
    <input type="text" name="teamName" value="${row.teamName }"/>
   </p>
   <p>&nbsp;</p>

<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/dmd" user="root" password="root"/>
<sql:query dataSource="${snapshot}" var="result">
 SELECT * from employee;
 </sql:query>

    <p>Employee ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:
    <select name="eid">
         <option>
       <c:forEach items="${result.rows}" var="row">
       <option value="${row.empID}"><c:out value="${row.EmpID}"/></option>
       </c:forEach>
          </option>

        </select>
        <p>&nbsp;</p>


  <p>Location No From&nbsp;&nbsp;&nbsp;:
    <input type="text" name="location" id="location" value="${row.location }"/>
  </p>
  <p>&nbsp;</p>

  <p>Location No To&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:
    <input type="text" name="location2" id="location2" value="${row.location2 }"/>
  </p>
  <p>&nbsp;</p>

  <p>Total Seats&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:
    <input type="text" name="totalSeats" id="totalseats" value="${row.totalSeats }"/>
  </p>
  <p>&nbsp;</p>

  <p>Valid From&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:
    <input type="text" name="from1 "id="datepicker" value="${row.from1 }"/>
    </p>
  <p>&nbsp;</p>

  <p>Valid To&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:
    <input type="text" name="to1" id="datepicker1" value="${row.to1 }" />
</p>
<p>&nbsp;</p>

  <p>Comments&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:
    <input type="text" name="comments" id="comments" value="${row.comments }"/>
  </p>
  <p>&nbsp;</p>

  <input type="submit" name="submit" value="ASSIGN"/>

<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
     url="jdbc:mysql://localhost/dmd"
     user="root"  password="root"/>


<sql:update dataSource="${snapshot}" var="result">
INSERT INTO assignseats VALUES ('+eid+','+employeeName+','+teamName+','+companyName+','+location+','+location2+','+totalSeats+''+from1+','+to1+','+comments+');
</sql:update>

<sql:query dataSource="${snapshot}" var="result">
SELECT * from assignseats;
</sql:query>

<table border="1" width="100%">
<tr>
   <th>Emp ID</th>
   <th>Employee Name</th>
   <th>Company Name</th>
   <th>Team Name</th>
   <th>Valid From</th>
   <th>Valid To</th>
   <th>Location From</th>
   <th>Location To</th>
   <th>Total Seats</th>
   <th>Comments</th>

</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
   <td><c:out value="${row.eid}"/></td>
   <td><c:out value="${row.employeeName}"/></td>
   <td><c:out value="${row.companyName}"/></td>
   <td><c:out value="${row.teamName}"/></td>
   <td><c:out value="${row.totalSeats}"/></td>
   <td><c:out value="${row.from1}"/></td>
   <td><c:out value="${row.to1}"/></td>
   <td><c:out value="${row.location}"/></td>
   <td><c:out value="${row.location2 }"/></td>
   <td><c:out value="${row.comments }"/></td>
</tr>
</c:forEach>
</table>
 </fieldset>
 </form>
</body>
</html>
Posted

Are you trying to insert data into the databaee?
In that case, look at the insert query and ensure the number of columns you are inserting match those that are in the database.
 
Share this answer
 
Apart from solution 1 by Abhinav, try to rewrite your sql queries using sql:param, read more: jstl-1-1-simple-insert-update-delete-example/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900