• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem of insert data into database

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Below is my form
----------------

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>

<%-- Connect to ms excel --%>
<sql:setDataSource var="mp"
driver="sun.jdbc.odbc.JdbcOdbcDriver"
url="jdbc:odbc:mp-list" />


<sql:query var="rs" dataSource="${mp}">
SELECT * FROM [MP$]
</sql:query>


<html>
<head>
<title>New Plan Form</title>
</head>
<body>


<form name="form" action="dispaly.jsp" method="post">
Plan Id: <input name="planId" type="text" size="6" value="${param.planId}"/><br/>

<table>
<tr>
<td>No</td>
<td>Part Id </td>
<td>Mps Qty</td>
</tr>
<c:set var="i" value="1" />
<c:forEach var="Row" items="${rs.rows}">

<tr>
<td><c:out value="${i}"/>. </td>
<td><input name="partId" type="text" size="25" value="${Row.PartId}" /></td>
<td><input name="qty" type="text" size="15" value="${Row.MpsQty}" /></td>
</tr>

<c:set var="i" value="${i+1}" />

</c:forEach>

<tr>


<td><input type="submit" name="submit" value=" Next " /></td>
</tr>
</table>
</form>

</body>
</html>
________________________________________________________________________

this is display.jsp
-------------------



<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>


<%-- Connect to ms access --%>
<sql:setDataSource var="connection"
driver="sun.jdbc.odbc.JdbcOdbcDriver"
url="jdbc:odbc:db1" />


<sql:update dataSource="${connection}">
INSERT INTO Temp values (?,?,null)
<sql:param value="${param.partId}"/>
<sql:param value="${param.qty}"/>
</sql:update>
______________________________________________________________________

first i read 10 rows of partId and qty from excel file into textbox, so that i can pass the parameters to display.jsp to insert to ms access database

the problem is only the first row is inserted to database
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chen,
Welcome to JavaRanch!

Please note that it is horrible practice to have SQL in JSPs. Those tags are only meant for prototyping.

<sql:update dataSource="${connection}">
INSERT INTO Temp values (?,?,null)
<sql:param value="${param.partId}"/>
<sql:param value="${param.qty}"/>
</sql:update>


This adds one row. I don't see a loop or anything that indicates inserting more than one row in the code.
 
CN
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Jeanne.

Can you tell me how to solve this problem?
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Chen Nee Lim:
thanks Jeanne.

Can you tell me how to solve this problem?


In a servlet call request.getParameterValues(). Loop through those results, calling a JDBC update statement for each one.

To improve performance, you could use a JDBC batch statement. For questions about JDBC, feel free to post in our JDBC forum after taking a look at the JDBC tutorial.

Also note that you will need to merge the two parameters into one so they get submitted together. A common technique is to format them as partId_quantity and tokenize that on the server.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic