【发布时间】:2015-02-28 14:38:53
【问题描述】:
代码连接到 mySQL 数据库并创建一个用数据填充它的表。每行都有一个特定于该行的购买按钮。所以具体的商品代码发送到jsporder.jsp页面。
<sql:query var="result">
select * from inventory;
</sql:query>
<table border="1" width="100%">
<tr>
<th>Code</th>
<th>Author</th>
<th>Description</th>
<th>Other field(Probs price)</th>
<th>Item Stock</th>
<th>Order Stock</th>
<th>Buy option </th>
</tr>
<c:forEach var = "row" items = "${result.rows}">
<tr>
<td><c:out value = "${row.item_code}"/></td>
<td><c:out value = "${row.item_author}"/></td>
<td><c:out value = "${row.item_description}"/></td>
<td><c:out value = "${row.item_price}"/></td>
<td><c:out value = "${row.item__stock_count}"/></td>
<td><c:out value = "${row.item_order_count}"/></td>
<td><a href="jsporder.jsp?item_code=${row.item_code}">Buy!</a></td>
<td><a
</tr>
</c:forEach>
</table>
</div>
现在我的 Jsp 订单页面我想更改数据库中的数据。
首先使用:
String itemCode = request.getParameter("item_code");
我认为它是从上一页获取 item_code 的?
现在我有需要更改的 mySQL 查询:
<sql:update var="count">
<%-- update inventory - take one item from stock --%>
update inventory set item__stock_count = item__stock_count - 1
where item_code="${itemCode}"; //This is set to the itemCode variable
</sql:update>
item_code 与 itemCode 不匹配。它似乎没有选择 itemCode 作为任何东西,因此它不会更改数据库中的值/在数据库中添加任何条目。
itemCode 变量似乎对 jsp/mysql 不存在。
新的网络开发人员。谢谢(额外)
<sql:update var="count">
<%-- add new customer_order --%>
insert into customer_order values
( '${itemCode}' "2015-02-24 11:42:30", 1,
"2015-02-25 11:42:30", 5789 );
</sql:update>
页面上显示的内容:
insert into customer_order values ( '' "2015-02-24 11:42:30", 1, "2015-02-25 11:42:30", 5789 ); : Column count doesn't match value count at row 1"
【问题讨论】:
-
This code does not seem to work。你到底得到了什么。正确解释? -
@singhakash 抱歉,已编辑。
-
@singhakash 100% 做,多次检查数据库。错误可能是它在字符串中提取 item_code(因为它有引号)例如,如果我在 item_code 上单击购买:A001-1111 将 SQL/JSP 将其拾取为“A001-1111”所以它不会匹配数据库上的值?
-
是的,您必须将
'${itemCode}'放在单引号中 -
@singhakash 仍有错误,在编辑中添加了更多代码