Jcombo box

Jcombo box

I want To add ittem in JComboBox which is stored in Mysql Database.

Database Column name -Course Items -MBA,MCA,MBA IT,MBA FINANCE I want Load Database records in to my JComboBox.

View Answers

March 4, 2011 at 4:53 PM

Retrieve values from database and stored it into JComboBox:

import java.sql.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class  JComboBoxExample {
    public static void main(String[] args) 
    {
        JFrame f=new JFrame();
        f.setLayout(null);
        JLabel lab=new JLabel("Course Items:");
        final JComboBox combo=new JComboBox();
        combo.addItem("--Select--");
        try{
        Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from student");
           while(rs.next()){
           combo.addItem(rs.getString("course_items"));
           }
        }
        catch(Exception e){}
        JButton b=new JButton("Get");
        lab.setBounds(20,20,100,20);
        combo.setBounds(120,20,150,20);
        b.setBounds(120,50,80,20);
        b.addActionListener(new ActionListener(){
         public void actionPerformed(ActionEvent e){
        String value = combo.getSelectedItem().toString();

        JOptionPane.showMessageDialog(null,"You have selected '"+value+"' from ComboBox");
         }
         });
        f.add(lab);
        f.add(combo);
        f.add(b);
        f.setVisible(true);
        f.setSize(300,120);
    }
}









Related Tutorials/Questions & Answers:
Jcombo box
Jcombo box  I want To add ittem in JComboBox which is stored in Mysql Database. Database Column name -Course Items -MBA,MCA,MBA IT,MBA FINANCE I want Load Database records in to my JComboBox
JCombo Box problem
JCombo Box problem  I have three combo boxes First combo box display the year Second combo box display the month for the selected year.ADS_TO_REPLACE_1 Third combo box display number of week in a selected month for the year
Advertisements
Jcombo box - Swing AWT
Jcombo box  Hello sir i found dis site today...realy superb evn i complete half project with ur examples sir i hav problem related to combo box i hav 3 combox c1, c2, c3 c1 contains items A, B, C, D c2 contains items E, F, G
Error with JCombo Box - Java Beginners
Error with JCombo Box  when i set JComboBox on Tab then Display Error near addItem method,that is Identifer Expected, How I Can remove that Error.  Hi Friend, Please post your code. Thanks
ModuleNotFoundError: No module named 'box-box'
ModuleNotFoundError: No module named 'box-box'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'box-box' How to remove the ModuleNotFoundError: No module named 'box-box
ModuleNotFoundError: No module named 'box-box'
ModuleNotFoundError: No module named 'box-box'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'box-box' How to remove the ModuleNotFoundError: No module named 'box-box
HTML in the box
HTML in the box  Can I use any HTML in the box
input box
input box  give me the code of input box in core java
input box
input box  give me the code of input box in core java
select box and text box validations
select box and text box validations  hi, any one please tell me how to set validations for select box and text boxes using bean classes? thank you   Please visit the following link: http://www.roseindia.net/jsp/user
dropdown box
dropdown box  i need to have country,state and city in drop down box using ajax and use db2 database   Have a look at the following link: JSP dependent dropdown
Hollow Box
Hollow Box  Write an application program that will draw a hollow box (a box with empty space in between). The program will ask the user to key... to exit. For example, if the user keys in 8, the hollow box (of length and width
dialog box
dialog box to show latest question  hello. write an application that displays a series of at least four interview questions and each question should... of the interview, use a dialog box to ask whether the user wants to - enter another set
dialog box
dialog box to ask to quit or continue  hello. write an application that displays a series of at least four interview questions and each question... of the interview, use a dialog box to ask whether the user wants to - enter another set
combo box
combo box  Hi, [_|] dropdown box [ ] [INCLUDE... a screen like this using jsp-servlet(or DAO,DTO),in that drop down box i should get
dialog box
dialog box  hello. write an application that displays a series of at least four interview questions and each question should have at least three possible numeric choice answers. at the end of the interview, use a dialog box
dialog box
dialog box  hello. write an application that displays a series of at least four interview questions and each question should have at least three possible numeric choice answers. at the end of the interview, use a dialog box
dialog box
dialog box  hello. write an application that displays a series of at least four interview questions and each question should have at least three possible numeric choice answers. at the end of the interview, use a dialog box
dialog box
dialog box  hello. write an application that displays a series of at least four interview questions and each question should have at least three possible numeric choice answers. at the end of the interview, use a dialog box
dialog box
dialog box  hello. write an application that displays a series of at least four interview questions and each question should have at least three possible numeric choice answers. at the end of the interview, use a dialog box
dialog box
dialog box  hello. write an application that displays a series of at least four interview questions and each question should have at least three possible numeric choice answers. at the end of the interview, use a dialog box
dialog box
of the interview, use a dialog box to ask whether the user wants to - enter another set
dialog box
. at the end of the interview, use a dialog box to ask whether the user wants
dialog box
. at the end of the interview, use a dialog box to ask whether the user wants
How to create an input box?
How to create an input box?  How to create an input box
What is a prompt box?
What is a prompt box?  What is a prompt box
How to create a confirmation box?
How to create a confirmation box?  How to create a confirmation box
box +15
box +15  i want help to complete this program. import java.util.*; class Mgic2{ public static void main(String []args){ Random r=new Random(); int [][] magic=new int[3][3]; boolean v15=true; while(v15){ int
javascript confirm box
javascript confirm box  javascript confirm box
combo box - JSP-Servlet
combo box  how to get a combo box in jsp page which allows editing as well as list box
autosuggest box - Ajax
autosuggest box Java example  How to implement auto suggest box using Ajax-DWR technology in jsp/html
Text box Checking
Text box Checking  I want to Write only the word A-Z in a text box What is the code
populate Combo Box dynamically
populate Combo Box dynamically  Hi, How to populate the Combo Box dynamically using Flex with Jsp's
how to insert check box
how to insert check box   how to insert check box into jtable row in swing
check box left justification
check box left justification  how to make a check box left justification which is at right end? thanks in advance
ModuleNotFoundError: No module named 'box'
ModuleNotFoundError: No module named 'box'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'box' How to remove the ModuleNotFoundError: No module named 'box' error
ModuleNotFoundError: No module named 'box'
ModuleNotFoundError: No module named 'box'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'box' How to remove the ModuleNotFoundError: No module named 'box' error
change appearance of alert box
change appearance of alert box  how to change the appearance of an alert() box
jquery dialog box center
jquery dialog box center  How to create dialog box with center alignment in jquery..?   $('my-selector').dialog('option', 'position', 'center
click on check box
click on check box  I create a check box in HTML and when i click on my check box relative information in page store in database
two text box problem
two text box problem  i have two text box in two different pages and same variable use in two text box when enter value in first text box it's reflection show in second text box , how i reduce it in jsf ?   Hi Friend
Uninstall Oracle Virtual Box
Uninstall Oracle Virtual Box  Hi, Is there any video of uninstalling Oracle Virtual Box? Thanks
Popup dialog box in java
Popup dialog box in java  How to display popup dialog box in java?   Dialog Box- A dialog box is an independent small window which appear... can create popup dialog box. Java swing toolkit provide tow types of dialog box
msg box in jsp
msg box in jsp  i need the source code to display the msgbox in jsp....but one condition is,i need to use it in the current page itself...now i use the message box means it prints it into another page...i need to resolve it plz
check box in jsp
check box in jsp  hey guys i am working on a web based project using jsp. In my project 1 am having 9 check boxes in 3 rows in the same form. I want to select 1 check box from each row and also i want to avoid many check box
dialog box size allignment
dialog box size allignment  actually i have 1 button,when clicked on it has to show dialog box containing 14 rows and 3 columns(jtextfield... box only i am able to view the 14 rows and 3 columns of data.with out resizing how
interrelated two selection box
interrelated two selection box  hi i need two selection box .in 1 box all designation like manager, ceo etc , onclick on manager i should get list of managers names in second selection box.. like wise so on. from database
List Box - JSP-Servlet
list box.on selecting one value in list box,i will retrieve values from database and store into another list box in same page using javascript :location.my problem is in first list box,value which i selected to get values is not displaying
date in combo box
date in combo box  strong texthello, how can i desplay the current year and next year in combo box???!!! it must be uppdate atumaticaly every year>>>
Servlets and confirm box
Servlets and confirm box  Sir...! I want to insert or delete records form oracle based on the value of confirm box can you please give me the idea.... thanks

Ads