non-static variable username cannot be referenced from a static content

46 Views Asked by At

I've written this test code:

        try {            
            com.mysql.jdbc.Connection koneksi = (com.mysql.jdbc.Connection) DriverManager.getConnection("jdbc:mysql://10.10.10.51/db_apps_ad", "root", "");
            koneksi.createStatement().executeUpdate("INSERT INTO tbl_presensi VALUES (NULL,'"
                    + getCurrentDateTime() + "',NULL,NULL'"
                    + getIPAddress() + "','"                    
                    + username.getText() + "')");
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

But it gives the following error:

non-static variable username cannot be referenced from a static content in line "+ username.getText() + "')");"

How do I get my methods to recognize my class variables?

I have tried creating a string object with the name String username = username.getText(); in the main method. Then called him by username but still didn't work. I hope your friends' answers can solve my program

0

There are 0 best solutions below