how to connect with data base with access sheet. in my application form there is two JTextArea and Two JComboBox.
Is this Access database or excel sheet. Do you want to display the values in Textarea and Combobox?
Please specify some more details.
I AM WRITING THE CODE HERE PLS GIVE ME A DEMO CONNECT WITH ACCESS DATABASE..... import java.util.*; import java.io.*; import java.sql.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class Air { public static void main(String []args) { JFrame frame=new AirFrame(); frame.setVisible(true); frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE); } } class AirFrame extends JFrame implements ActionListener { JPanel panel; JPanel panel1; JPanel panel2; JLabel title; JLabel aircode,source,destination; JComboBox cb,cb1,cb2; JButton save,reset,exit; public AirFrame() { setSize(1024,720); setLocation(120,40); setResizable(false); setTitle("Air-Line"); Container contentPane=getContentPane(); title=new JLabel("Radhe Krishna Air-Line Ticket Reservation"); title.setSize(1024,40); title.setLocation(250,20); title.setFont(new Font("Lucida Handwriting", Font.PLAIN, 24)); title.setForeground(Color.red); aircode=new JLabel("AIRCODE"); aircode.setSize(200,20); aircode.setLocation(120,120); aircode.setFont(new Font("Times New Roman", Font.PLAIN, 20)); aircode.setForeground(Color.green); String[] Aircode={ "Select AirCode", "Jet Airways", "Kingfisher Airways" }; cb = new JComboBox(Aircode); cb.setSelectedIndex(0); cb.setSize(150, 20); cb.setLocation(230,120); source=new JLabel("SOURCE"); source.setSize(200,20); source.setLocation(120,170); source.setFont(new Font("Times New Roman", Font.PLAIN, 20)); source.setForeground(Color.green); String[] Source={ "Select Source","Agartala","Agatti Island","Agra","Ahmedabad","Aizawl","Allahabad","Amritsar","Aurangabad","Bagdogra","Bangalore","Belgaum","Bellary","Bengaluru","Bhavnagar","Bhopal","Bhubaneshwar","Bhuj","Bikaner","Bombay","Calcutta","Calicut","Chandigarh","Chennai","Cochin","Coimbatore","Dehradun","Delhi","Dharamshala","Dibrugarh","Dimapur","Diu","Gaya","Goa","Gorakhpur","Guwahati","Gwalior","Hubli","Hyderabad","Imphal","Indore","Jabalpur","Jagdalpur ","Jaipur","Jammu","Jamnagar","Jamshedpur","Jindal","Vidyanagar","Jodhpur","Jorhat","Kandla ","Kanpur ","Khajuraho","Kochi","Kolhapur","Kolkata","Kulu","Latur","Leh","Lilabari","Lucknow","Ludhiana","Madras","Madurai","Mangalore","Mumbai","Mysore ","Nagpur ","Nanded","Nasik ","New Delhi","Pantnagar","Pathankot","Patna","Porbandar","Port Blair ","Pune","Raipur","Rajahmundry","Rajkot","Ranchi","Salem","Shillong ","Shimla ","Sholapur","Silchar","Srinagar","Surat","Tezpur","Thiruvananthapuram","Tiruchirapally","Tirupati","Trichy","Trivandrum","Tuticorin","Udaipur","Vadodara","Varanasi","Vijayawada","Vishakhapatnam" }; cb1 = new JComboBox(Source); cb1.setSelectedIndex(0); cb1.setSize(150, 20); cb1.setLocation(230,170); destination=new JLabel("DESTINATION"); destination.setSize(200,20); destination.setLocation(550,170); destination.setFont(new Font("Times New Roman", Font.PLAIN, 20)); destination.setForeground(Color.green); String[] Destination={ "Select Destination","Agartala","Agatti Island","Agra","Ahmedabad","Aizawl","Allahabad","Amritsar","Aurangabad","Bagdogra","Bangalore","Belgaum","Bellary","Bengaluru","Bhavnagar","Bhopal","Bhubaneshwar","Bhuj","Bikaner","Bombay","Calcutta","Calicut","Chandigarh","Chennai","Cochin","Coimbatore","Dehradun","Delhi","Dharamshala","Dibrugarh","Dimapur","Diu","Gaya","Goa","Gorakhpur","Guwahati","Gwalior","Hubli","Hyderabad","Imphal","Indore","Jabalpur","Jagdalpur ","Jaipur","Jammu","Jamnagar","Jamshedpur","Jindal","Vidyanagar","Jodhpur","Jorhat","Kandla ","Kanpur ","Khajuraho","Kochi","Kolhapur","Kolkata","Kulu","Latur","Leh","Lilabari","Lucknow","Ludhiana","Madras","Madurai","Mangalore","Mumbai","Mysore ","Nagpur ","Nanded","Nasik ","New Delhi","Pantnagar","Pathankot","Patna","Porbandar","Port Blair ","Pune","Raipur","Rajahmundry","Rajkot","Ranchi","Salem","Shillong ","Shimla ","Sholapur","Silchar","Srinagar","Surat","Tezpur","Thiruvananthapuram","Tiruchirapally","Tirupati","Trichy","Trivandrum","Tuticorin","Udaipur","Vadodara","Varanasi","Vijayawada","Vishakhapatnam" }; cb2 = new JComboBox(Destination); cb2.setSelectedIndex(0); cb2.setSize(150, 20); cb2.setLocation(710,170); save=new JButton("SAVE"); save.setSize(150,20); save.setLocation(350,600); save.setFont(new Font("Times New Roman", Font.PLAIN, 20)); save.setForeground(Color.green); save.addActionListener(this); reset=new JButton("RESET"); reset.setSize(150,20); reset.setLocation(550,600); reset.setFont(new Font("Times New Roman", Font.PLAIN, 20)); reset.setForeground(Color.green); reset.addActionListener(this); exit=new JButton("EXIT"); exit.setSize(150,20); exit.setLocation(750,600); exit.setFont(new Font("Times New Roman", Font.PLAIN, 20)); exit.setForeground(Color.green); exit.addActionListener(this); panel=new JPanel(); panel.setLayout(null); panel.setSize(1024, 100); panel.setLocation(0, 0); panel.setBackground(Color.blue); panel1=new JPanel(); panel1.setLayout(null); panel1.setSize(1024, 100); panel1.setLocation(0, 0); panel1.setBackground(Color.PINK); panel2=new JPanel(); panel2.setLayout(null); panel2.setSize(1024, 100); panel2.setLocation(0, 0); panel2.setBackground(Color.BLUE); contentPane.add(panel); contentPane.add(panel1); contentPane.add(panel2); panel.add(title); panel2.add(aircode); panel2.add(cb); panel2.add(source); panel2.add(cb1); panel2.add(destination); panel2.add(cb2); panel2.add(save); panel2.add(reset); panel2.add(exit); } public void actionPerformed(ActionEvent e) { // i try the give below code but not store the value// Object obj = e.getSource(); if (obj==save) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:db1"); PreparedStatement stat= con.prepareStatement("insert into table1 values(?,?,?)"); stat.setString(1,cb.getName()); stat.setString(2,cb1.getName()); stat.setString(3,cb2.getName()); stat.executeUpdate(); JOptionPane.showMessageDialog(null,"Record updated"); con.close(); } catch(Exception err) { JOptionPane.showMessageDialog(null," "+err); } } if(obj==exit) { System.exit(0); } if (obj==reset) { } } }
Ads