Connect J ComboBox with Databse

Connect J ComboBox with Databse

Hello Sir I want To Connect MS Access Database with JComboBox ,
when I Select any Item from Jcombobox Related Records will Display in to JTextBox
eg
when i select MBA then fees ,Duration ,course type will automatically
display on the Form.
plz Help Me Sir
View Answers

March 20, 2010 at 2:58 PM

Hi Friend,

Try the following code:

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

public class SwingFrame{
public static void main(String[] args) throws Exception{
SwingFrame sf=new SwingFrame();
}
public SwingFrame(){
JFrame f = new JFrame("Frame in Java Swing");
f.getContentPane().setLayout(null);
JLabel lbl1 = new JLabel("Select Course");
final JComboBox jc=new JComboBox();
jc.addItem("Select");
jc.addItem("MCA");
jc.addItem("MBA");
jc.addItem("BE");
jc.addItem("BTech");
jc.addItem("Others");
JLabel lbl2 = new JLabel("Duration");
final JTextField jt1=new JTextField(15);
JLabel lbl3 = new JLabel("Fees");
final JTextField jt2=new JTextField(15);
lbl1.setBounds(50,50,100,20);
jc.setBounds(170,50,100,20);
lbl2.setBounds(50,80,70,20);
jt1.setBounds(170,80,100,20);
lbl3.setBounds(50,110,70,20);
jt2.setBounds(170,110,100,20);

jc.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
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+"'");
int duration=0;
int fees=0;
while(rs.next()){
duration=rs.getInt("duration");
fees=rs.getInt("fees");
}
jt1.setText(Integer.toString(duration));
jt2.setText(Integer.toString(fees));
}
catch(Exception ex){}
}
});
f.add(lbl1);
f.add(lbl2);
f.add(lbl3);
f.add(jt1);
f.add(jt2);
f.add(jc);
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]);
}
}

Thanks









Related Tutorials/Questions & Answers:
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
Connect J ComboBox with Databse - Java Beginners
Connect J ComboBox with Databse  Hello Sir I want To Connect MS Access Database with JComboBox , when I Select any Item from Jcombobox Related Records will Display in to JTextBox eg when i select MBA then fees ,Duration
Advertisements
how to connect two databse through HibernateFramework
how to connect two databse through HibernateFramework  how to connect two databse through HibernateFramework
comboBox validation
comboBox validation  dear sir. i want to know . how to validate radio button in struts using xml validation. thanks
to jsp combobox exmple
to jsp combobox exmple  to jsp combobox exmple
Flex Combobox
Flex Combobox  flex combobox with database as dataprovider   You can visit the following link for detailed tutorial on the topic. May this will be helpful to you. http://www.roseindia.net/flex/flex-combo-box.shtml
J
J
Flex Combobox
Flex Combobox  flex combobox with database as dataprovider  ... backgroundColor = '#CCCCFC' width = '100%' height = '100%'> <mx:ComboBox...; <mx:ComboBox x = '200' color = 'green'> <mx:dataProvider>
combobox
combobox
combobox
combobox
combobox
convert system.out.print( p[ j ] +
convert system.out.print( p[ j ] +   how to display this on midlet? for( int j = 0; j < p.length; j++ ){ System.out.print( p[ j
jsp combobox
jsp combobox  ihave three tables in database country,state and city..if i select one country throug combo box than other combobox show state only select country ...than city how i can implement through jsp   1
ModuleNotFoundError: No module named 'j'
ModuleNotFoundError: No module named 'j'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'j' How to remove the ModuleNotFoundError: No module named 'j' error
ComboBox in Flex4
ComboBox in Flex4: In Flex4 Combobox is called a spark Combobox control. DropDownListBase control is the base class of the combobox control. Combobox control works like a DropDownList control. When we click on the combobox control
editable combobox method selection
editable combobox method selection  how to make an editable combobox that shows nothing initially but as a key is pressed it pops up and selects an item starting with that letter, subsequent keys would keep sorting from the list
how to use an editable combobox
how to use an editable combobox   Hello Everyone!!!!!!!! I have a jcombo box with certain values and i want to use it as an editable that means when user will type something in combobox, according to that text only matching item
fill combobox at runtime jsp
fill combobox at runtime jsp  i have 1 combobox in jsp which... another combobox below it, i want it to be filled on the basis of selected value of 1st combobox...plz help with code
two linked combobox
two linked combobox  give jsp example of two combo box when i select state in one combobox in second combo box cities will display according to state which i select
doubt in combobox in flex - XML
doubt in combobox in flex  hi, i have doudt in combobox in flex which is a combination of mxml and actioscript . In my project i has a combobox with 10 items when i select the particular item i has 2 display
Connect to the database
Connect to the database  how to connect to the database in the iphone
combobox cannot be resolved in JavaFX
combobox cannot be resolved in JavaFX  I want to design one application with a combobox containing items. and while selecting i want to give user autocomplete suggestion. but while doing this combobox is not getting resolved. i
Combobox application - Swing AWT
Combobox application  hi, i am facing a problem in updation of the comboboxes i m using in an application...for the first time the selectec item does is not returned and thus i am unable to pass it as an argument to another
combobox updation - Java Beginners
combobox updation  hi, i am using java swing to develop a gui.... It is required that on clicking a specific menu-the first combobox is populated using a vector, and then on clicking on a specific combobox item, the 2nd and 3rd
j - Java Beginners
(); for (int j = 0; j < selected.length; j++) { selected1.add(selected[j
values in combobox - Java Beginners
values in combobox  how to fill values in combo box i.e. select tag in html using javascript?   Hi Friend, Try the following code: ComboBox var arr = new Array(); arr[0] = new Array("-select-"); arr[1
ComboBox ItemRenderer in DataGrid
ComboBox ItemRenderer in DataGrid  Hi..... How can I create custom combo box itemtenderer in the flex datagrid? please give me an example.....ADS...; <mx:ComboBox > <mx
Bar chart with J table
Bar chart with J table  Hi I'm new in Java and I have a application that reads multiple text files and displays them in a Jtable.So can you please tell me how can I make a bar graph that will display the data from my table.I
ModuleNotFoundError: No module named 'J_box'
ModuleNotFoundError: No module named 'J_box'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'J_box' How to remove the ModuleNotFoundError: No module named 'J_box'
ModuleNotFoundError: No module named 'J_box'
ModuleNotFoundError: No module named 'J_box'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'J_box' How to remove the ModuleNotFoundError: No module named 'J_box'
ModuleNotFoundError: No module named 'nester_j'
ModuleNotFoundError: No module named 'nester_j'  Hi, My Python... 'nester_j' How to remove the ModuleNotFoundError: No module named 'nester_j... to install padas library. You can install nester_j python with following
ModuleNotFoundError: No module named 'nester_j'
ModuleNotFoundError: No module named 'nester_j'  Hi, My Python... 'nester_j' How to remove the ModuleNotFoundError: No module named 'nester_j... to install padas library. You can install nester_j python with following
ModuleNotFoundError: No module named 'serial-j'
ModuleNotFoundError: No module named 'serial-j'  Hi, My Python... 'serial-j' How to remove the ModuleNotFoundError: No module named 'serial-j... to install padas library. You can install serial-j python with following
ModuleNotFoundError: No module named 'j-builds'
ModuleNotFoundError: No module named 'j-builds'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'j-builds' How to remove the ModuleNotFoundError: No module named 'j-builds
ModuleNotFoundError: No module named 'j-crypto'
ModuleNotFoundError: No module named 'j-crypto'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'j-crypto' How to remove the ModuleNotFoundError: No module named 'j-crypto
ModuleNotFoundError: No module named 'J-nester'
ModuleNotFoundError: No module named 'J-nester'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'J-nester' How to remove the ModuleNotFoundError: No module named 'J-nester
ModuleNotFoundError: No module named 'j-test'
ModuleNotFoundError: No module named 'j-test'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'j-test' How to remove the ModuleNotFoundError: No module named 'j-test'
Combobox program - Java Beginners
Combobox program  import javax.swing.*; import java.awt.*; public class SwingFrame1 { public static void main(String[] args) throws Exception... in combobox a new text box have to open beside that combo box..  Hi
Version of plj>pl-j dependency
List of Version of plj>pl-j dependency
Version of com.hynnet>pdf-j dependency
List of Version of com.hynnet>pdf-j dependency
Version of com.jukta>j-tahoe dependency
List of Version of com.jukta>j-tahoe dependency
how to insert data from netbeans into databse
how to insert data from netbeans into databse  how to insert data from netbeans into databse   Please visit the following link: http://www.roseindia.net/webservices/web-services-database.shtml
Combobox jsp from 0 to 10
Combobox jsp from 0 to 10  Hi guys please help me to write a very easy program using jsp to display value in combobox from 0 to 10. How to write the for loop? Please help.Thank!!!   <html> <select> <
FLEX 3 Combobox - Development process
and just started tinkering with Adobe Flex. I have downloaded your combobox... a combobox - once selected - it will show the airport code into a text field. Example: ComboBox Chicago,Illinois Boise, Idaho Buffalo, New York Baltmore
how to select second combobox value .
how to select second combobox value .  I requirement is , i have two combo box, i am selected first combo box value then automatically second combo box value show ,But this both combo box value i retrieves in database. please
How to Display values from databse into table
How to Display values from databse into table  I want to display values from database into table based on condition in query, how to display... Connect Example."); Connection conn = null; String url = "jdbc:mysql://localhost:3306
MySql Databse query to fetch results from database
MySql Databse query to fetch results from database  Hi. I have a field in database named stages. its datatype is varchar(60). It contains values chennai,trichy,kanchipuram for a single record. I have to retrieve these data from

Ads