Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
**Below is my code in my jsp file**

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

</button>







**Below is my sql query I used... When I click on dropdown on my jsp webpage, and select a product from the list, that product's ID must be fetched and update in another table in same database. Please help me how to resolve this issue.**

public void selectProductsString(RecipieColumns2 rc2) throws SQLException {




1. I have a jsp file which has dropdown containing product names which are fetched from the sql table. 2. My problem is, when i click the product name from the drop down, it should fetch the productID associated with the product name from the database and that product ID should be updated in another table. So everytime I select product name, it's product ID must be updated in another SQL table**

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);
}

}

1. First code is jsp file which has dropdown containing product names which are fetched from the sql table. 2. My problem is, when i click the product name from the drop down, it should fetch the productID associated with the product name from the database and that product ID should be updated in another table. So everytime I select product name, it's product ID must be updated in another SQL table**
Posted

1 solution

If I understand your problem correctly then here is what you want to do -
You have two web pages where first one contains project name (drop down box)
Second web page contains some other fields where you are accepting values from user related to the product selected in first web page
Now you want to save second page fields in database table along with product id of product selected in first page

If this is correct then here is my suggestion
1) Write code on "Index_Change" even of "Product" drop down box to get the product id from database and store that Id into cookie
2) Navigate to second page and store all fields along with id from cookie into database table

--
RDBurmon
Make sense
If yes then please accept and vote my solution
 
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