473,406 Members | 2,343 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,406 software developers and data experts.

SQL Statement based on JCombobox selection

Here is the actionMouseClicked. It should be able to update the selected row with new data from a form.
The updating works for the most part I.e It updates all data in one column to the same data (which is fine as long as I can get the SQL to work)

I need it so the SQL statement recognizes the ComboBox selection and updates the database accordingly.


Expand|Select|Wrap|Line Numbers
  1.  
  2. private void addBtnMouseClicked(java.awt.event.MouseEvent evt) {                                    
  3.  
  4.         String CBox2 =(String)comboBoxCS.getSelectedItem();        
  5.  
  6.         String sql = "update carstock set CarStock = ? where DriverID = ('CBox2')";
  7.  
  8.         try{
  9.             pst = conn.prepareStatement(sql);
  10.             pst.setString(1, addRemove.getText());
  11.  
  12.  
  13.             pst.executeUpdate();
  14.             JOptionPane.showMessageDialog(null, "Updated");        
  15.             UpdateJTable();
  16.         }
  17.         catch (Exception e){
  18.             JOptionPane.showMessageDialog(null, e);
  19.         }
  20.  
  21.     }      
  22.  
Mar 21 '13 #1
1 2425
r035198x
13,262 8TB
Add an ActionListener to your combobox then in the actionPerformed method do
Expand|Select|Wrap|Line Numbers
  1. if(e.getSource() instanceof JComboBox) {
  2.  JComboBox cb = (JComboBox)e.getSource();
  3.  String selectedValue= (String)cb.getSelectedItem();
  4. //do something with the selected value
  5. }
Mar 22 '13 #2

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

Similar topics

9
by: | last post by:
Is it possible to construct a CDO.To statement based on the value of an incoming form drop down list which contains any word such as "ChangeStatus:" How would I construct the IF statement to...
3
by: Antoine Janssen | last post by:
hi, I would like to create two combo boxes. In the first one you can select a user in the second one you can select a project. To simplify the selection i would like to shorten the project list...
9
by: Alex | last post by:
Hi, Is it possible to perform a swicth statement based on a range of values ? eg. switch(Answer) case : 0 - 4 : do something; break;
1
by: thegame | last post by:
Filling One DataGrid Based on Selection from Another DataGrid - Both in Separate User Controls Hello, I have an interesting dilemma. I have an ASPX page with two user controls (two ASCXs). ...
5
by: STeve | last post by:
Hey guys, I currently have a 100 page word document filled with various "articles". These articles are delimited by the Style of the text (IE. Heading 1 for the various titles) These articles...
0
by: ROO | last post by:
Hi Everyone, I have a database table that have 4 field( C1, C2, M1, M2) on my form i have two combo box ComboC and ComboM C1 C2 M1 M2 1 ...
7
imrosie
by: imrosie | last post by:
Hellol, I'm again in need of your help with my Order processing system.. My Order form is based on (query) of Customer and Order tables (includes a subform for the product data)...has a listbox...
2
by: jujubean | last post by:
I have a form with five comboboxes. In the first, the user can select one of four items. The other four comboxes are hidden. Based on the selection made in combobox one, I would like one of the...
10
by: JohnO | last post by:
Hi All, This question is related to iSeries V5R4 and db2. I want to implement an AFTER DELETE trigger to save the deleted rows to an archive table, I initially defined it as a FOR EACH...
3
by: Venturini | last post by:
I am trying to put together a web page where the customer makes choices of products and is then given a total. I am extremely new to Javascript and have managed to get as far as I have from web...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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.