How to store JComboBox selected Item into Ms Access Database.
April 10, 2010 at 11:06 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 Value. In this tutorial we are discussing about
how to
store
the
selected item value of
JComboBox into the
database table. To
store the
selected item value of
JComboBox...
how to get the
selected item value form
JComboBox.
javax.swing.JComboBox
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
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
How to Access MS Access in jar.How to
Access MS Access in jar.
how do i
access my
Ms-
Access file... to
access it via Code or is their any alter-native?? Do i need any Driver to do this ... i m able to
access a
Ms-
access via JDBC but cant find the file wen
How to use JTable with MS-AccessHow to use JTable with
MS-Access I have Three Column in
Database (
MS-
Access).
1. Name
2. City
3. Contact
I want to Display....
Here is an example that retrieves the data from
MS Access database How to use JTable with MS-AccessHow to use JTable with
MS-Access I have Three Column in
Database (
MS-
Access).
1. Name
2. City
3. Contact
I want to Display....
Here is an example that retrieves the data from
MS Access database applet connected to table in MS Access database applet connected to table in
MS Access database i have connected my java code with the
MS access database and this is my code, can anyone tell me
how to show the table in an applet...pls
import java.sql.
ms accessms access
how to delete the autonumber from
ms access using java delete code
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
MS accessMS access
how do i
access my
Ms-
Access file placed in the same jar file where my application code/class file r present??? Want to
access it via Code. Can anyone help me ? Please give reply urgent...
give me reply
How to store image into databaseHow to
store image into database Hi, all I want to
store image into
database using Java. Can anyone help me that
how can i
store image into
database... through the following link
How To
Store Image Into MySQL Using Java
Updating Ms Access Database using jsp - JSP-ServletUpdating
Ms Access Database using jsp Hi
I am new to jsp and I am trying to update a record in an
access database. I only want to update part of the record because the other columns already have data. When I use Update
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
Ms Access Ms Access How to get query for Primary key from MsAccess?
SELECT column_name
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE table_name = 'data';
SELECT column_name
FROM INFORMATION_SCHEMA.KEY_COLUMN
J2ME connectivity to ms accessJ2ME connectivity to
ms access
How to establish client server connectivity to
access ms access database on the server side? I have made the odbc connection. Plz help me in the coding part.. Dont know
how to start
MS Access` - IDE QuestionsMS Access` hello sir,
how to configure
MS Access database in Net Beans5.5...
and i have a doubt, where should we run the below code...either in IDE or in any editor like EDITPLUS.
waitin for your reply....
thank you
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
MS Access` - JDBC to insert image into
MS Access Database. Now the task is
how to retrieve the image from
database. And i am developing a JFrame to retrieve tha fields from
database...
MS Access` Hello Sir,
Thank you very much for your valuable
MS-AccessMS-Access I am trying to upload a image to
ms-acess using jsp,and my problem is that it shows some error int the browser that "java.sql.SQLException: [Microsoft][ODBC Microsoft
Access Driver]COUNT field incorrect ".I think i set