import java.awt.*;
import javax.swing.*;
import java.sql.*;
import javax.swing.text.MaskFormatter;
import javax.swing.table.DefaultTableModel;
import java.util.Vector;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;

class MyFrame extends JFrame implements ActionListener,MouseListener{
		Container c;
		JLabel lAccountNo,lAName,lDateofOpng,lAddress,lContactNo,lTotalBalance;
		JTextField tAName,tContactNo,tTotalBalance;
		JTextArea tAddress;	
		JFormattedTextField tDateofOpng,tAccountNo;
		JButton bAdd,bNew,bDelete,bExit,bUpdate;
		DefaultTableModel mAccthld;
		JTable tAcctHld;
	MyFrame(){
		c=getContentPane();
		setSize(Toolkit.getDefaultToolkit().getScreenSize());
		setTitle("Account Holder");
		setLayout(null);
		
		lAccountNo=new JLabel("AccountNo.");
		lAccountNo.setBounds(25,25,150,50);
		c.add(lAccountNo);
		
		lAName=new JLabel("Name");
		lAName.setBounds(25,125,150,50);
		c.add(lAName);
		
		lDateofOpng=new JLabel("DateofOpening");
		lDateofOpng.setBounds(25,225,150,50);
		c.add(lDateofOpng);
		
		lAddress=new JLabel("Address");
		lAddress.setBounds(25,325,150,50);
		c.add(lAddress);
		
		lContactNo=new JLabel("Contact No.");
		lContactNo.setBounds(25,425,150,50);
		c.add(lContactNo);
		
		lTotalBalance=new JLabel("Total balance");
		lTotalBalance.setBounds(25,525,150,50);
		c.add(lTotalBalance);
		try {
    
	     	tAccountNo=new JFormattedTextField(new MaskFormatter("11100###########"));
		    tAccountNo.setBounds(250,25,150,50);
		    c.add(tAccountNo);
		}
		 catch(Exception ex){
		 }
		 
		
		tAName=new JTextField();
		tAName.setBounds(250,125,150,50);
		c.add(tAName);
		
		try {
		tDateofOpng=new JFormattedTextField(new MaskFormatter("####-##-##"));
			tDateofOpng.setBounds(250,225,150,50);
			c.add(tDateofOpng);
    
         }
			catch (Exception ex) {
			}
		
		tAddress=new JTextArea();
		tAddress.setLineWrap(true);
		JScrollPane jspAddress=new JScrollPane(tAddress);
		jspAddress.setBounds(250,325,150,50);
		c.add(jspAddress);
		
		tContactNo=new JTextField();
		tContactNo.setBounds(250,425,150,50);
		c.add(tContactNo);
		
		tTotalBalance=new JTextField();
		tTotalBalance.setBounds(250,525,150,50);
		c.add(tTotalBalance);
		
String s[]={"Acct No.","Name","Date of openg","Address","Contact No.","Total Balance"};
		mAccthld=new DefaultTableModel(s,0);
	//	fillTable();
		tAcctHld=new JTable(mAccthld);
		JScrollPane jsp=new JScrollPane(tAcctHld);
		jsp.setBounds(550,0,600,600);
		c.add(jsp);
		
		bAdd=new JButton("Add");
		bAdd.setBounds(25,600,100,50);
		c.add(bAdd);
		bAdd.addActionListener(this);
		
		bNew=new JButton("New");
		bNew.setBounds(150,600,100,50);
		c.add(bNew);
		
		bUpdate=new JButton("Update");
		bUpdate.setBounds(275,600,100,50);
		c.add(bUpdate);
		
		bDelete=new JButton("Delete");
		bDelete.setBounds(650,625,100,50);
		c.add(bDelete);
	
		
		bExit=new JButton("Exit");
		bExit.setBounds(800,625,100,50);
		c.add(bExit);
		bExit.addActionListener(this);
		
	
		
		
		c.setBackground(Color.GRAY);	
		setVisible(true);
		setDefaultCloseOperation(3);
	
	}
	    public void actionPerformed(ActionEvent ae){
	    	Object o=ae.getSource();
	    	if (o.equals(bAdd)){
	    try {	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
						Connection.on=DriverManager.getConnection("jdbc:odbc:DRIVER=Microsoft Access Driver (*.mdb);DBQ=fddata.mdb");
PreparedStatement st=con.prepareStatement("insert into accthld Values(?,?,?,?,?,?)"); 
                st.setInt(1,Integer.parseInt(tAccountNo.getText()));
			st.setString(2,tAName.getText());
                            	st.setString(3,tAddress.getText());
			st.setInt(4,Integer.parseInt(tDateofOpng.getText()));
			st.setInt(5,Integer.parseInt(tContactNo.getText()));
			st.setInt(6,Integer.parseInt(tTotalBalance.getText()));
			st.executeUpdate();
							
			con.close();
						
                 }
                 catch (Exception ex) {
                 	System.out.println(ex.toString());
                 }
	    	Vector v=new Vector();
		v.add(Integer.parseInt(tAccountNo.getText()));
			v.add(tAName.getText());
		  
			v.add(tAddress.getText());
			v.add(Integer.parseInt(tContactNo.getText()));
		v.add(Integer.parseInt(tTotalBalance.getText()));
			mAccthld.addRow(v);
	    	}
	    	else if(o.equals(bNew)){
	    	}
	    	else if(o.equals(bUpdate)){
	    	}
	    	else if(o.equals(bDelete)){
	    	}
	    	else if(o.equals(bExit)){
	    		dispose();
	    	}
	    }
	    		
}

	    
	    
	    



 
public class AcctHld {
    
    public static void main(String[] args) {
    	
    	
    	new MyFrame();
    	//new FrmAdd();
    }
}[/I]

it is giving an exception java.sql.sqlexception nd i made a change in this i remove parseint method from line147 nd constants given in jformattedtextfield in line 52

Lines 55/57 are a very bad idea. If an exception is thrown you have chosen to ignore it completely. Unless you are expecting the exception and know that it's OK, you should always start out by printing all the info related to the exception:

catch (Exception ex) {
  ex.printStackTrace();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.