
i WANT HELP RELATED TO JDBC CONNECTIVITY WITH MS ACCESS..
HERE IS MY FULL CODE...
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.swing.*;
public abstract class New_Customer extends JFrame implements ActionListener,ItemListner
{
JTextField textFieldId;
JTextField textFieldName;
JTextField textFieldContactNo;
JLabel l1;
JLabel l2;
JLabel l3;
JLabel l4;
JLabel l5;
JLabel l6;
JComboBox combo;
ComboBox b = new ComboBox();
String course[] = {"Navakal","SandhyaKal","Pudhari","MidDay","Inqlab","BusinessLine","Mumbai Samachar","Gujraj Samachar","Karnatak Malla","Vartahar","PunyaNagari"};
JButton b1;
JButton b2;
PreparedStatement ps;
Container c = getContentPane();
New_Customer()
{
super("Shree DattaDigambar Samarth");
setBounds(140,250,777,555);
c.setLayout(null);
textFieldId = new JTextField();
textFieldName = new JTextField();
textFieldContactNo = new JTextField();
l1 = new JLabel("New Customer Entry");
l2 = new JLabel("Building No");
l3 = new JLabel("Customer Name");
l4 = new JLabel("Contact No");
l5 = new JLabel("Paper");
combo = new JComboBox(course);
l1.setBounds(10,10,340,20);
l2.setBounds(10,20,140,70);
l3.setBounds(110,20,140,70);
l4.setBounds(300,50,140,20);
l5.setBounds(400,50,140,20);
textFieldId.setBounds(10,70,70,20);
textFieldName.setBounds(110,70,180,20);
textFieldContactNo.setBounds(300,70,90,20);
combo.setBounds(400,70,130,20);
b1 = new JButton("Add paper");
b2 = new JButton("Ok");
b1.setBounds(10,100,100,20);
b2.setBounds(10,160,50,20);
c.add(combo);
c.add(b1);
c.add(b2);
c.add(l1);
c.add(l2);
c.add(l3);
c.add(l4);
c.add(l5);
c.add(textFieldId);
c.add(textFieldName);
c.add(textFieldContactNo);
setVisible(true);
setDefaultCloseOperation(EXITONCLOSE);
b1.addActionListener(this);
b2.addActionListener(this);
combo.addItemListener(null);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b2)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con;
con = DriverManager.getConnection("jdbc:odbc:Digambar_Dalvi");
ps=con.prepareStatement("insert into Customer(Building_No,Customer_Name,Contact_No,Paper_Name)values(?,?,?,?)");
ps.setString(1,textFieldId.getText());
ps.setString(2,textFieldName.getText());
ps.setString(3,textFieldContactNo.getText());
ERROR{ String str = (String)combo.getSelectedItem();
ERROR ps.setString(4,combo.getText());
ERROR //ps.setString(4,str.getText());
ERROR ps.executeUpdate();
}
con.close();
}
catch(Exception ex)
{
System.out.println("Error 1:"+ex);
}
}
}
public static void main(String args[])
{
New_Customer v = new New_Customer() {};
}
}
AS I SHOW IN CODE THE ERROR PART...... THE QUESTION N PROBLEM IS I WANT TO SELECTE PERTICULAR PAPER FROM COMBOBOX AND THOSE SELECTED PAPER TEXT I WANT TO PRINT IN MS ACESS DATABASE..MEANS FROM THAT I COME TO KNOW THAT WHICH CUSTOMER HAVING WHICH PAPER........... HELP ME PLZ THANKS IN ADVANCED
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.