Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Janki
Jcombo box
1 Answer(s)      3 years and 8 months ago
Posted in : Java Beginners


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.


Advertisement
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. Third combo box display number of week in a selected month for the year. I am select 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
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
HTML in the box
HTML in the box  Can I use any HTML in the box
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 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
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
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
. 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
dialog box
of the interview, use a dialog box to ask whether the user wants to - enter another set
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
How to create a confirmation box?
How to create a confirmation box?  How to create a confirmation box
What is a prompt box?
What is a prompt box?  What is a prompt box
How to create an input box?
How to create an input box?  How to create an input box
javascript confirm box
javascript confirm box  javascript confirm box
check box left justification
check box left justification  how to make a check box left justification which is at right end? thanks in advance
how to insert check box
how to insert check box   how to insert check box into jtable row in swing
populate Combo Box dynamically
populate Combo Box dynamically  Hi, How to populate the Combo Box dynamically using Flex with Jsp's
Text box Checking
Text box Checking  I want to Write only the word A-Z in a text box What is the code
Advertisements
 

 

 

DMCA.com