jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/Users/Kix/Desktop/IMPORTANT DOCS/oop/BANKSYSTEM/Accounts.mdb;DriverID=22;READONLY=false}
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at banksystem.BankDBDriver.retrieveData(BankDBDriver.java:200)
        at banksystem.BankSystem.actionPerformed(BankSystem.java:109)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
        at java.awt.Component.processMouseEvent(Component.java:6267)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
        at java.awt.Component.processEvent(Component.java:6032)
        at java.awt.Container.processEvent(Container.java:2041)
        at java.awt.Component.dispatchEventImpl(Component.java:4630)
        at java.awt.Container.dispatchEventImpl(Container.java:2099)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
        at java.awt.Container.dispatchEventImpl(Container.java:2085)
        at java.awt.Window.dispatchEventImpl(Window.java:2478)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package banksystem;

/**
 *
 * @author Kix
 */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import banksystem.CreateAccount;
import banksystem.Account;

public class BankSystem extends JFrame implements ActionListener{



    JLabel lblAccount, lblPassword,lblCreateAcct, lblLine;
    JTextField tfAccount;
    JPasswordField pass;
    static JButton btnConfirm, btnCreate;
    GridBagLayout gbl;
    GridBagConstraints gbc;

    static Connection con;
    static Statement stmt;
    static ResultSet rs;


    public BankSystem(String title){
        super(title);
        gbl=new GridBagLayout();
        setLayout(gbl);
        gbc=new GridBagConstraints();

        lblAccount = new JLabel("Account : ");
        lblPassword = new JLabel("Password : ");
        lblCreateAcct = new JLabel("Dont have an account yet?");
        lblLine = new JLabel("__________________________________________");

        tfAccount = new JTextField(10);
        pass = new JPasswordField(10);
        pass.setEchoChar('*');

        pass.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent e) {
        System.out.println(new String(pass.getText()));
      }
    });


        btnConfirm = new JButton("OK");
        btnCreate = new JButton("Create Account");



        gbc.fill=GridBagConstraints.HORIZONTAL;
        addComponent(  lblAccount,1,0,1,1);
        gbc.fill=GridBagConstraints.HORIZONTAL;
        addComponent(tfAccount,1,1,1,2);

        gbc.fill=GridBagConstraints.HORIZONTAL;
        addComponent( lblPassword,2,0,1,1);
        gbc.fill=GridBagConstraints.HORIZONTAL;
        addComponent(pass,2,1,1,2);


        gbc.fill=GridBagConstraints.BOTH;
        addComponent(btnConfirm,3,1,1,1);
        addComponent(lblLine,4,0,1,4);
        addComponent(lblCreateAcct,5,0,1,2);
        addComponent(btnCreate,6,0,1,1);

        btnConfirm.addActionListener(this);
        btnCreate.addActionListener(this);
        pack();
        closeWindow();
        setSize(350,300);
        setVisible(true);



    }

 public void addComponent(Component c,int row,int col,int nrow,int ncol){
        gbc.gridx=col;
        gbc.gridy=row;

        gbc.gridwidth=ncol;
        gbc.gridheight=nrow;
        gbl.setConstraints(c, gbc);
        add(c);

    }
 public void actionPerformed(ActionEvent a) {
     if (a.getSource()==btnCreate){
         CreateAccount ca = new CreateAccount("");
         this.dispose();

     }
     if (a.getSource()==btnConfirm){
         BankDBDriver.loadDriver();
         BankDBDriver.makeConnection();
         BankDBDriver.retrieveData();
     }
 }
 public void retrieveData() {

       try {
           stmt= con.createStatement();
            String gdta ="select Account,Password,FirstName,LastName,MiddleName,Month,Araw,Year,Address,Email,ZipCode,Contact from Accounts";
           //String gdta="SELECT Account,Password,Balance FROM Accounts WHERE Account = '"+CreateAccount.tfAccountName.getText()+"'"
              //     + "AND Password = '"+CreateAccount.Password.getText()+"' AND Balance ='"+Deposit.tfAmount.getText()+"' ";
           //step 6: process the results.
           //if(CreateAccount.tfAccountName.getText().equals("Account")&&CreateAccount.Password.getText().equals("Password")){
           rs = stmt.executeQuery(gdta);
           while (rs.next()) {

               String a = rs.getString("Account");
              int b = rs.getInt("Balance");

                System.out.println(a);
                 System.out.println(b);
               // Account.lblAccount1.setText(a);
               // Account.lblBalance.setText(b);
                //Account ac = new Account("");
           }

     }
       catch(SQLException ex) {
           System.err.println("RetrieveData: " + ex.getMessage());
       }
     }

 private void closeWindow(){

        addWindowListener(
            new WindowAdapter(){
                public void windowClosing(WindowEvent we){
                    System.exit(0);
                }
            }
        );

    }
 public static void main(String args[]){
        BankSystem b = new BankSystem("Opening Frame");

    }


}

Recommended Answers

All 7 Replies

Please do not double post in the future. There is 30 min period you can always edit your post to add new information

Line 109 you are calling BankDBDriver.retrieveData(); is throwing error. I presume you have another class BankDBDriver that you need to post before we can help you. Or was that above line mistake and you just wanted to call retrieveData() that is on line 112?

that is only retrieveData();

i forgot to delete the BankDBDriver. before retrieveData();

Connection at line 115 is null because you did only call methods to establish connection, but never actually assigned to the one that you declared on 30. You just call for it with

BankDBDriver.loadDriver();
BankDBDriver.makeConnection();

but that connections stays in your BankDBDrviver class. Give makeConnection() method return type of Connection and assign it to "con" so you can use it in this class

error(s) comings just from dbConnection, GUI is correct,

how should i do that it gives me an error because the makeConnection() method has void result type

the connection that i am using with my inserting gui to database and selecting gui to database are the same... but only the inserting gui is running without the same error..
BUT the selecting gui have that error..

again that's nothing to do with GUI

1/ GUI in this form is Static, you are able to change it/set by method
public void retrieveData() {, debug that and check which JComponent generated
java.lang.NullPointerException
2/ hint: you have to initialize (set value) for your JComponents (TextComponents)

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.