JComboBox with AccessDatabase

JComboBox with AccessDatabase

Hello Sir I have Created Course(CourseId,CourseName,Fees,Duration,Type) form
then I want To Display Course Details on Student Admission Form
when I select Course Name from JComboBox on Student Admission Form ,that Time I will Get The Course Details Automatically on Student Admission Form in The TextBox.
Plz Help Me Sir
View Answers

March 19, 2010 at 4:05 PM

Hi Friend,

Try the following code:

import java.sql.*;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;

class StudentAdmissionForm{
public static void main(String[] args) throws Exception{
StudentAdmissionForm sf=new StudentAdmissionForm();
}
public StudentAdmissionForm(){
JFrame f = new JFrame("Frame in Java Swing");
f.getContentPane().setLayout(null);
JLabel lbl1 = new JLabel("Name");
JTextField jt1=new JTextField(15);
JLabel lbl2 = new JLabel("Address");
JTextField jt2=new JTextField(15);
JLabel lbl3 = new JLabel("Gender");

JRadioButton Male,Female;
ButtonGroup radioGroup=new ButtonGroup();
Male=new JRadioButton("Male");
radioGroup.add(Male);
Female=new JRadioButton("Female");
radioGroup.add(Female);
JLabel lbl4=new JLabel("Date Of Birth");
JComboBox combo1=new JComboBox();
JComboBox combo2=new JComboBox();
JComboBox combo3=new JComboBox();
for(int i=1;i<=31;i++){
combo1.addItem(i);
}
for(int i=1;i<=12;i++){
combo2.addItem(i);
}
for(int i=1980;i<=2010;i++){
combo3.addItem(i);
}
JLabel lbl5=new JLabel("Contact No");
JTextField jt3=new JTextField(15);
JLabel lbl6=new JLabel("Select Course");
JComboBox combo=new JComboBox();
combo.addItem("B Tech");
combo.addItem("M Tech");
combo.addItem("MBA");
combo.addItem("MCA");

final JTextArea area=new JTextArea(10,20);
final JScrollPane pane=new JScrollPane(area);

lbl1.setBounds(50,50,70,30);
lbl2.setBounds(50,80,70,30);
lbl3.setBounds(50,110,70,30);
lbl4.setBounds(50,140,100,30);
lbl5.setBounds(50,170,100,30);
lbl6.setBounds(50,200,70,30);
jt1.setBounds(170,50,200,25);
jt2.setBounds(170,80,200,25);
Male.setBounds(170,110,100,30);
Female.setBounds(270,110,100,30);
combo1.setBounds(170,140,50,25);
combo2.setBounds(270,140,50,25);
combo3.setBounds(370,140,80,25);
jt3.setBounds(170,170,200,25);
combo.setBounds(170, 200,100,30);
pane.setBounds(170,240,200,100);

f.add(lbl1);
f.add(lbl2);
f.add(lbl3);
f.add(lbl4);
f.add(lbl5);
f.add(jt1);
f.add(jt2);
f.add(jt3);
f.add(combo1);
f.add(combo2);
f.add(combo3);
f.add(Male);
f.add(Female);
f.add(combo);
f.add(pane);

combo.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
pane.setVisible(true);
ItemSelectable is = (ItemSelectable)e.getSource();
String st= selectedString(is);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:access","","");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from course where name='"+st+"'");
String strVal="";
while(rs.next()){

ArrayList al = new ArrayList();
al.add("ID= "+rs.getString(1));
al.add("Course= "+rs.getString(2));
al.add("Duration= "+rs.getString(3));
al.add("Fees= "+rs.getString(4));
Iterator itr = al.iterator();
while(itr.hasNext())
{
strVal+= itr.next().toString()+"\n";
}
}
area.setText(strVal);
}
catch(Exception ex){}
}
});

pane.setVisible(false);
f.setSize(1000,1000);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
static private String selectedString(ItemSelectable is) {
Object selected[] = is.getSelectedObjects();
return ((selected.length == 0) ? "null" : (String)selected[0]);
}
}

For the above code, create table course(id,name,duration,fees).

Thanks









Related Tutorials/Questions & Answers:
JComboBox with AccessDatabase - Java Beginners
JComboBox with AccessDatabase  Hello Sir I have Created Course... on Student Admission Form when I select Course Name from JComboBox on Student..."); JComboBox combo1=new JComboBox(); JComboBox combo2=new JComboBox
JComboBox
JComboBox  I want to change the index of one jComboBox according to the selected index of another jComboBox. I can do it.Also the user should have the ability to select or change the index of the second combobox according
Advertisements
jComboBox
jComboBox  I want to change the index of one jComboBox according to the selected index of another jComboBox. I can do it.Also the user should have the ability to select or change the index of the second combobox according
JComboBox
JComboBox  I have jcombobox. In which tha values are loaded from MySql Database. My problem is that i want to load content of the jtable whenever i change the selected item. Please some one help me to do this. Thank you
jcombobox
jcombobox  hi i have developed a form and i have jcombobox in which data is retrieved from ms access but the problem is that if we pressed the down key the last 5 data are not showed only the other data can be pressed
JComboBox
have jcombobox on Jframe form of IDE. In which the values are to be loaded from... change the selected item in JComboBox. Thank you. (adsbygoogle... JLabel("Select"); final JComboBox combo=new JComboBox
Jcombobox
Jcombobox  Hii, I am doing my final year project and i am using java swing as a front end.I have used Jcombobox for displaying my on bluetooth devices and i also made a refresh button.when i click on the refresh button i
issue on jcombobox
issue on jcombobox  i have JTextfield and JComboBox. there are several values in combobox.when i select a value from combobox how to make textfiled as a combobox.only few values in the combobox need this functionality. need
jComboBox with database
jComboBox with database  Hello friends, I have created three JComboBoxes. first two of them get list from string. However I select these two comboboxes, the third combobox automatically retrieve data of a particular column from
JComboBox on JRadioButton - Java Beginners
JComboBox on JRadioButton  How to add JComboBox on Jpanel ,Give Me Sample Code
Help on database and JComboBox
Help on database and JComboBox  I want to select from the JComboBox and when click onto the "search" button, the selected category (example "new york") all the each new york picture and detail will be seen. But how to grab
About jcombobox - Swing AWT
About jcombobox  Hi all, I am new to this forum. Can we do auto suggest jcombobox in swing? If yes is there any jar file for that or any code... JTextField tf; private final JComboBox combo = new JComboBox(); private
JComboBox Event Handling - Java Beginners
JComboBox Event Handling  Hi, I have problem with event handling here.There are Two JComboBox and a JTextField.When I select an item in first... Compare extends JFrame implements ItemListener { JComboBox combo,lcombo
problem with addactionlistener on JComboBox - Java Beginners
[] = { "A", "B", "C"}; JFrame frame = new JFrame(); JComboBox combo = new JComboBox(st); frame.add(combo); ActionListener actionListener = new
Changing JLabel with a jcombobox - Java Beginners
listener event of JComboBox put JLabel.setText("Put yourtext here
Link To Database with JComboBox - Java Beginners
course names from Access Database in to JComboBox but now I want to do ,when i select Course name from Jcombobox i want to display appropriate records relate..."); final JComboBox jc=new JComboBox(); JLabel lbl2 = new JLabel("Duration"); final
JComboBox Display Problem - Java Beginners
JComboBox Display Problem  I am create one program that contain two...,ItemListener { Container c; JLabel lblstart,lblend; JComboBox cmbstart..."); lblend=new JLabel("End Date"); cmbstart=new JComboBox(); cmbend=new
How to store JComboBox item into database
How to store JComboBox item into database   import... DefaultComboBoxModel(labels); final JPanel TypeTF = new JPanel(); JComboBox comboBox1 = new JComboBox(model); comboBox1.setEditable(false
Create a JComboBox Component in Java
Create a JComboBox Component in Java       In this section, you will learn about the JComboBox Component of swing in java. The JComboBox is used to display drop-down list
Database values in JComboBox
Database values in JComboBox In this section, you will learn how to display values in JComboBox from database. For this, we have allowed the user to enter... JFrame(); f.getContentPane().setLayout(null); final JComboBox combo = new
easy way to make a JCombobox look like a JTextField?
easy way to make a JCombobox look like a JTextField?  Is there a good(and easy) way to make a JCombobox look like a JTextField? By this I mean there should not be a dropdown button, but when the user enters something it should
binding jComboBox to mysql database - Swing AWT
binding jComboBox to mysql database  I am using netbeans 6.5 How to populate jComboBox with data of specific column of mysql database table? I...){ e.printStackTrace(); } JComboBox comboTypesList = new
How to Add JComboBox on JPanel - Java Beginners
How to Add JComboBox on JPanel  How to Add JComboBox on JPanel D:\java>javac ViewElements.java ViewElements.java:181: expected...); JLabel lbl4=new JLabel("Branch"); final JComboBox jc=new JComboBox(); jc.addItem
JComboBox Insert Edited Value Into Table
JComboBox Insert Edited Value Into Table In this section we will read about how to make JComboBox an editable and then how to insert the new edited value... in to insert an editable value of JComboBox into a table. We will use an Java editor
Add Items in JComboBox from Access Database - Java Beginners
Add Items in JComboBox from Access Database  Heelo Sir I want To add ittem in JComboBox which is stored in Access Database. plz Help Me Sir... records in to my JComboBox.   Hi Friend, Try the following code
How to store JComboBox selected Item into Ms Access Database - Java Beginners
How to store JComboBox selected Item into Ms Access Database  How to store JComboBox selected Item into Ms Access Database.  Hi Friend..."); f.getContentPane().setLayout(null); JLabel lbl1=new JLabel("Branch"); final JComboBox jc
How to save JCombobox Selected Item in to Access Database - Java Beginners
How to save JCombobox Selected Item in to Access Database  How to save JCombobox Selected Item in to Access Database  Hi Friend, Try...().setLayout(null); JLabel lbl1=new JLabel("Branch"); final JComboBox jc=new
Load Coursenames from MS Acess Database to JComboBox - Java Beginners
"); final JComboBox jc=new JComboBox(); try{ Class.forName
navigation between panels when item is selected from jcombobox - Swing AWT
on JComboBox in Java visit to : http://www.roseindia.net/java/example/java/swing
Java JComboBox Get Selected Item Value
Java JComboBox Get Selected Item Value In this section we will discuss about how to get the selected item value form JComboBox. javax.swing.JComboBox... of JComboBox into the database table. To store the selected item value of JComboBox
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access
show null point Exception """ while trying 2 load a JComboBox"" data is fetch...*; import java.sql.*; class Comboo extends JFrame { JComboBox jcb; Connection con...().setBackground(d); setDefaultCloseOperation(JFrame.EXITONCLOSE); jcb=new JComboBox
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access
show null point Exception """ while trying 2 load a JComboBox"" data is fetch...*; import java.sql.*; class Comboo extends JFrame { JComboBox jcb; Connection con...().setBackground(d); setDefaultCloseOperation(JFrame.EXITONCLOSE); jcb=new JComboBox
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access
show null point Exception """ while trying 2 load a JComboBox"" data is fetch...*; import java.sql.*; class Comboo extends JFrame { JComboBox jcb; Connection con...().setBackground(d); setDefaultCloseOperation(JFrame.EXITONCLOSE); jcb=new JComboBox
Combo box In Java
a value in the editable field. Combo box can be created using JCombobox in java.... Constructor of JCombobox are as follows: JComboBox() : Create a combo box with a default. JCombobox(ComboBoxModel a) : Create a combo box that accept
Jlist
JcomboBox to a Jlist  How to transfer a data from a JcomboBox to a Jlist ? Each time I select 1 item from a JComboBox, it will display in a JList
Non-edit Combobox with auto fill - Swing AWT
JCombobox with auto fill capability. Auto fill is working only for the first character... in JCombobox model. When user type 'C', JCombobox selects "Callisto...-editable mode of JCombobox, For ex: If user type "Ch" JCombobox should select
JFormattedTextField issue
to place a JFormattedTextField inside a JComboBox. The JComboBox is in one of the JTable columns. The JComboBox holds a list of item and I also want the JComboBox... that JFormattedTextField inside the JComboBox. Thanks for help! Morongo
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
java code
java code  I am beginer in java my question is how can i fill data from mysql database to jcombobox using netbeans
Urgent requirement
Urgent requirement  I want to implement Autocompletion code for Jcombobox in swing can you please help me out from
how to access the MS ACCESS database with java
AccessDatabase{ public static void main(String[] args){ try...); } } } For deleting data: import java.sql.*; class AccessDatabase...: import java.sql.*; class AccessDatabase{ public static void main(String[] args
how to connect java with ms access using odbc in eclipse
how to connect java with ms access using odbc in eclipse  import java.sql.*; class AccessDatabase{ public static void main(String[] args){ try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver
combo program - Java Beginners
(); f.getContentPane().setLayout(null); JComboBox day=new JComboBox(); JComboBox month=new JComboBox(); JComboBox year=new JComboBox(); for(int i=1;i<=31;i
How to Connect J ComboBox with Databse - Java Beginners
How to Connect J ComboBox with Databse  How to Connect J ComboBox with Databse  Hi Friend, Do you want to get JComboBox values from database?Please clarify this. Thanks
swings - Java Beginners
frame; private JPanel panel; private JComboBox cBox1; private JComboBox cBox2; public TestCombo() { frame = new JFrame("Combo...); panel = new JPanel(); cBox1 = new JComboBox(); cBox2 = new
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
swings
swings  My program has different combo boxes i want to select all my components but when i select one JComboBox it's work if i selected next one the program terminates could you please tell me the answer
java swings - Java Beginners
java swings  Hi, I have JoptionPane combobox,in the joptionpane jcombobox have array of values. If i select one value from the joptionpane combobox ,then the selected value will be displayed in the listbox. Please send
multiple JComboBoxes using with JDBC
;); JComboBox jc1=new JComboBox(); JComboBox jc2=new JComboBox(); try
java swings - Java Beginners
java swings   Hi, I need the code for joptionpane with jcombobox. my requirement is click on add button,one joptionpane will come.from the option pane i need to select the combobox values. Please send the sample code

Ads