473,399 Members | 3,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Below is my sql query I used... When I click on dropdown on my jsp webpage, and selec

Expand|Select|Wrap|Line Numbers
  1. String sql1 = "select Products from [09RE]where RecName='Roasted Turkey Sandwich' and UU='uma'";
  2.         Connection connection = getConnection();
  3.         StringBuilder builder = new StringBuilder();
  4.                 try{
  5.                     PreparedStatement statement = connection.prepareStatement(sql1);
  6.  
  7.                     ResultSet results = statement.executeQuery();
  8.                     while(results.next()){
  9.                         String Products = results.getString("Products");
  10.                         String Product_list[] = Products.split(",");
  11.  
  12.  
  13.                         String sql = "select id from [09PR] where ProdName=? and UU='uma'";
  14.                         PreparedStatement statement1 = connection.prepareStatement(sql);
  15.                         //statement1.setString(1, rc2.getProdName());
  16.                         ResultSet results1 = statement1.executeQuery();
  17.                         while(results1.next()){
  18.                             String displaysql = sql;
  19.                             String id = results1.getString("id");   
  20.                                 builder.append(Products+","+id);
  21.                                 String totalProducts = builder.toString();
  22.                                 String sql2 = "update [09RE] set Products ='" + totalProducts +"' where UU='uma'";
  23.                                 PreparedStatement statement2 = connection.prepareStatement(sql2);
  24.  
  25.                                 statement2.executeQuery();
  26.                             }
  27.                     }
  28.  
  29.  
  30.                     }catch (SQLException e) {
  31.                         // TODO Auto-generated catch block
  32.                         e.printStackTrace();
  33.                     } finally {
  34.                         closeConnection(connection);
  35.                     }
  36.  
  37.         }
**
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**
May 21 '15 #1
1 1306
chaarmann
785 Expert 512MB
Why is line 15 commented out?
You are supposed to set the argument here which replaces the question mark in your sql in line 13.
You got all products in a list at line 10. So you must loop through this list one by one and each time call your sql.
There is a better way: you use the "in" statement if your DB supports it. Then you can fetch all IDs with one statement. I mean for example you can call:
Expand|Select|Wrap|Line Numbers
  1. select id from [09PR] where ProdName in ('myProduct1', 'product2', 'prod3') and UU='uma'
That means you must first transform you product array in a single string that represents a comma separated and single-quoted list of products, and then concatenate this string with your query string
May 22 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: msnews.microsoft.com | last post by:
Hello! I'm Jim by asp How can show "abc" in textbox when click one botton?
2
by: Santosh | last post by:
Hi, I have a script running which fails when it tries to execute an Update query, but when i try to run the query from the SQLQueryAnalyzer it runs fine. Can somebody try and explain this...
5
by: Miquel van Smoorenburg | last post by:
I have a database with a btree index on the 'removed' field, which is of type 'date'. However it isn't being used: techdb2=> explain select * from lines where removed > CURRENT_DATE; QUERY PLAN...
7
by: zwasdl | last post by:
When I swtich to design view from data view, the query results are lost, and I have to run again to get it. Is there an option in access to keep the data when I switching views? I know I can copy...
3
by: Paul | last post by:
Hi All, In my application, I wished to check certain things on each page load, so rather than paste the same code in each pages constructor, I thought it would be more logical to inherit from...
2
by: chandra131 | last post by:
Query used in cursor: DECLARE CURSOR2 CURSOR FOR SELECT TDET_DET_PAR_NBR ,TDET_SYS_ID ...
2
by: site | last post by:
Have to compare dates of two rows in one table Input table COL1| COL2| COL3| COL4 1| A| 1-Jan-07| 6-Feb-08 2| A| 7-Feb-08| 31-Mar-08 3| A| 1-Jan-09| NULL SQL code to compare COL 4 date (Row...
5
by: hidayu1986 | last post by:
how to disable textbox when click on radiobutton using VB script on Visual Studio.Net 2005. currently i used this coding but it is not functioning. Private sub...
0
by: vijay2591 | last post by:
I have crated tab link menu in ""Magento header""...when click on link color will change and after click on another link color change and previous link color back to original...I have created...
0
by: unnati1234 | last post by:
i have developed a drag and clone of image.now in that i want that when click on image it display browse dialog box for browse image from computer.and after selecting image it display on that...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.