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



Home Answers Viewqa Java-Beginners Connect J ComboBox with Databse
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


sushant
Connect J ComboBox with Databse
1 Answer(s)      4 years and 7 months ago
Posted in : Java Beginners


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

Advertisement
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
J
J
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
j - Java Beginners
(); for (int j = 0; j < selected.length; j++) { selected1.add(selected[j
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
comboBox validation
comboBox validation  dear sir. i want to know . how to validate radio button in struts using xml validation. thanks
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
to jsp combobox exmple
to jsp combobox exmple  to jsp combobox exmple
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>
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
Connect to the database
Connect to the database  how to connect to the database in the iphone
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
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
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
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
Struts validation for j-query tabs data
Struts validation for j-query tabs data  Hi, I want apply struts validation for J-query tabs data while saving into database, can any body tell please
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
How to connect
How to connect  how to connect to a remote host using jsp? We need to update files to the database of the application on the local machine from the updated database on our webpage
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
Java Blue J using smart turtle
Java Blue J using smart turtle  I wanted to know the code to start up my smart turtle? i think it goes something like smartTurtle = my smartTurtle ( i need this to be tell my trutle to draw
I cannott integrate j boss wth eclipse
I cannott integrate j boss wth eclipse   Dear friend, I have a sophisticated problem with my IDE eclipse.I am trying to start my ap server boss ,i have getting a eror that "server cannot start the time of 50 sec ". Please help
Mysql connect
Mysql connect  i can have a mysql database file and mysql-connector-net .but i have not mysql database. how to connect vb.net thsis database.(C:\Documents and Settings\Admin\My Documents\VB.NET\Stock delna\STC.sql ). plz help me
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
 

 

 

DMCA.com