Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 18095

JTextfield don't send the text to an another class

$
0
0

So im trying to a bank program in java. The login works great but i also want to display the money, the IBAN and the BIC but i need the login name to get these three. My problem is now that it doesn't send the login name from one class to an another class.

This is the code from the login class

 private void loginBankACC() throws SQLException {        //Making String's to access it easier        String anmldName = txtAnmeldename.getText();        String pwd = new String(pwdPasswort.getPassword());        Connection conn = DriverManager.getConnection(dbconnection, "root", "");        String strCheck = "Select * From bankkonten Where Anmeldename = " + anmldName +" And Passwort LIKE '" + pwd +"'";        PreparedStatement ps = conn.prepareStatement(strCheck);        ResultSet rset = ps.executeQuery();        //Making Strings to access it after the while-loop.         String anmldName1 = "";        String pwd1 = "";        while (rset.next()) {            anmldName1 = rset.getString("Anmeldename");            pwd1 = rset.getString("Passwort");        }        //Checking if the text in the field is the same from the database        if (anmldName.equals(anmldName1) && pwd.equals(pwd1)) {            dispose();            Hauptbankverbindung mf = new Hauptbankverbindung(null, true);            mf.setVisible(true);            mf.setAlwaysOnTop(true);        } else {            JOptionPane.showMessageDialog(this, "Falscher Anmeldename oder Passwort!", "ERROR", JOptionPane.ERROR_MESSAGE);        }    }    //Just to access it from another classes    public String getTxtAnmeldename() {        return txtAnmeldename.getText();    }

and this the code from the class where i want to get the login name

    //A method to get the information from the Database    private void getStringfromDB() throws SQLException {        LoginBank mf = new LoginBank(null, true);        //        String anmldname = mf.getTxtAnmeldename();        System.out.println(anmldname +" ??"); //-- Testing if the login  got sended        java.sql.Connection conn = DriverManager.getConnection(dbconnection, "root", "");        String strSet = "Select IBAN, BIC, Kontostand From bankkonten Where Anmeldename ='"+ mf.getTxtAnmeldename()+"'";        PreparedStatement ps = conn.prepareStatement(strSet);        ResultSet rset = ps.executeQuery(strSet);        while (rset.next()) {            //Getting the IBAN, BIC and Money to set it into the Dialoge            String iban = rset.getString("IBAN");            lblIBAN.setText(iban);            String bic = rset.getString("BIC");            lblBIC.setText(bic);            int kontostand = rset.getInt("Kontostand");            lblKontostand.setText(kontostand +"€");        }    }

i hope you understand my code

i already tried a getter and setter but it didn't worked out.Im not the best in coding but im trying to learn


Viewing all articles
Browse latest Browse all 18095

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>