Results 1 to 2 of 2
  1. #1
    harsimran05 is offline Member
    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    Default java.sql.sqlException

    [CODE]import java.awt.*;
    import javax.swing.*;import java.sql.*
    ;import 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:od bc: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();
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,442
    Rep Power
    18

    Default Re: java.sql.sqlException

    Wow.
    Nothing like giving us something to go on...

    You missed the close code tag.
    You also seem to have forgotten to give us the full stack trace and message from your exception, pointing out the line from which it is thrown in your code.

    Then (and only then) might we actually be able to help you.

    Some description of what your code is doing might help, depending on the actual problem.

Similar Threads

  1. java.sql.SQLException: Closed Connection
    By sunjavaboy in forum JDBC
    Replies: 4
    Last Post: 03-21-2012, 01:38 PM
  2. Replies: 0
    Last Post: 01-21-2011, 12:43 PM
  3. Replies: 6
    Last Post: 09-01-2010, 11:29 AM
  4. Replies: 2
    Last Post: 06-07-2010, 08:45 AM
  5. Unreported exception java.sql.SQLException
    By javamula in forum AWT / Swing
    Replies: 4
    Last Post: 09-29-2009, 02:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •