How to save JCombobox Selected Item in to Access Database
April 10, 2010 at 11:05 AM
Hi Friend,
Try the following code:
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
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("Branch");
final JComboBox jc=new JComboBox();
JButton b=new JButton("Insert");
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:access","","");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select name from course");
jc.addItem("Select");
while(rs.next()){
jc.addItem(rs.getString("name"));
}
}
catch(Exception e){}
lbl1.setBounds(100,120,70,20);
jc.setBounds(170,120,100,20);
b.setBounds(170,150,100,20);
f.add(lbl1);
f.add(b);
f.add(jc);
f.setSize(1000,1000);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String st= jc.getSelectedItem().toString();
System.out.println(st);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:access","","");
Statement stmt=con.createStatement();
int i=stmt.executeUpdate("insert into Student(Course) values('"+st+"')");
}
catch(Exception ex){
System.out.println(ex);
}
}
});
}
}
Thanks
Related Tutorials/Questions & Answers:
Advertisements
How to store JComboBox item into database How to store
JComboBox item into
database import...(javax.swing.SwingConstants.CENTER);
jLabel2.setText("
Item Code");
getContentPane().add(jLabel2,new...);
jLabel3.setText("
Item Name");
getContentPane().add(jLabel3,new AbsoluteConstraints(27
Java JComboBox Get Selected Item ValueJava
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 Access 2007 database connectivityAccess 2007
database connectivity i design an application form that have two
JComboBox as the label(source,destination) and two JButton
save and Exit. when i click at
SAVE Button than it doesn't
save the
selected item from
Help on database and JComboBoxHelp 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
jComboBox with database my
database. But in my code its only get data from first
item which...
jComboBox with database Hello friends,
I have created three JComboBoxes. first two of them get list from string. However I select these two
Link To Database with JComboBox - Java BeginnersLink To
Database with JComboBox sir As ur Source Code i have Load 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
how to access database in applethow to
access database in applet HI...
I'm having an applet where we should display the
database values in the applet...
It works fine in the local system(same network)...
but when its in the server, we r getting null values
How to access the database from JSP?How to
access the
database from JSP? Hi,
What is the process...
database from JSP which explains you
how to
access the
database by embedding... you can
access the
database by embedding the JDBC code. But this is not the best
nested selected tag ihave display selected item nested
selected tag ihave display
selected item i have two combo boxes combo1 combo1 in first combo box i taken as follows
select name="combo1">
option value="0">-select-
option value="1">INDIA
option value
JComboBoxJComboBox 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
how to access the MS ACCESS database with java how to
access the MS
ACCESS database with java
how to
access the MS
ACCESS database with java
how can we insert,delete,update,search records of ms
access with java
Java MS
Access database connectivity
Follow
Database values in JComboBoxDatabase 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... the
database will get
displayed on the ComboBox. If there will be no data
How to access (MySQL)database from J2ME?How to
access (MySQL)
database from J2ME? I am new to J2ME. I am using NetBeans.
Can anyone help me?
How to
access (MySQL)
database from J2ME?
( I search a lot I found that there is need to
access database through servlet
how to delete the access database value in jsphow to delete the
access database value in jsp i loaded my
database data into the dropdown list box...now i want to delete the value..plz send the source code to delete the value in dropdown list box and also from
database how to delete the access database value in jsphow to delete the
access database value in jsp i loaded my
database data into the dropdown list box...now i want to delete the value..plz send the source code to delete the value in dropdown list box and also from
database JComboBox have
jcombobox on Jframe form of IDE. In which the values are to be loaded from MySql
Database. My problem is that i want to load content of the jtable whenever i change the
selected item in
JComboBox.
Thank you.
(adsbygoogle
how to connect to MS access database in JSP?how to connect to MS
access database in JSP?
how to connect to MS
access database in JSP? Any seetings/drivers need to be set or installed before... and select the driver Microsoft
Access Driver(*.mdb).
3)After selecting the driver
binding jComboBox to mysql database - Swing AWTbinding
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
JComboBoxJComboBox 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
jComboBoxjComboBox 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