**Below is my code in my jsp file**
<table class="table" style="width:30%;">
<tr > <td>
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
Select product
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<% for(RecipieProductAllergen app1:RecipieProductAllergen) {
%>
<li role="presentation"><a name="ProdID" role="menuitem" tabindex="-1"
<c:url value="recipie.jsp" var="displayURL">
<c:param name="ProdID" value="${param.Name}" />
</c:url>
><%= app1.getProdID() %><%= app1.getProdName() %></a></li>
<%}%>
</ul>
</div></td>
</tr>
</table>
下面是我使用的SQL查询...当我点击我的jsp网页上的下拉列表,并从列表中选择一个产品时,必须获取该产品的ID并在另一个表中更新相同的数据库请帮我解决此问题。
public void selectProductsString(RecipieColumns2 rc2) throws SQLException {
String sql1 = "select Products from [09RE]where RecName='Roasted Turkey Sandwich' and UU='uma'";
Connection connection = getConnection();
StringBuilder builder = new StringBuilder();
try{
PreparedStatement statement = connection.prepareStatement(sql1);
ResultSet results = statement.executeQuery();
while(results.next()){
String Products = results.getString("Products");
String Product_list[] = Products.split(",");
String sql = "select id from [09PR] where ProdName=? and UU='uma'";
PreparedStatement statement1 = connection.prepareStatement(sql);
//statement1.setString(1, rc2.getProdName());
ResultSet results1 = statement1.executeQuery();
while(results1.next()){
String displaysql = sql;
String id = results1.getString("id");
builder.append(Products+","+id);
String totalProducts = builder.toString();
String sql2 = "update [09RE] set Products ='" + totalProducts +"' where UU='uma'";
PreparedStatement statement2 = connection.prepareStatement(sql2);
statement2.executeQuery();
}
}
}catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
closeConnection(connection);
}
}
由于