使用带有mySQL和JSP ERROR的URL参数

时间:2015-02-28 14:38:53

标签: html mysql jsp

代码连接到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?

现在我需要更改我的SQL查询:

<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"

1 个答案:

答案 0 :(得分:0)

将您的购买链接更改为

<a href="jsporder.jsp?itemCode=${row.item_code}">Buy!</a>

并从 jsporder.jsp 中删除以下内容,因为它不是必需的。

String itemCode = request.getParameter("item_code");

此外,您可能需要在更新查询中使用逗号。

  insert into customer_order values
    ( '${param.itemCode}', "2015-02-24 11:42:30", 1, 
                         ^
      "2015-02-25 11:42:30", 5789 );

验证您的customer_order表有五列并且具有匹配的数据类型。