0

Class Code

this is some of code from Class Code that may help.

private ResultSet rs;
private Connection cn;
private Statement st;    

public void insertData(String data)

{
    try
    {
        st.executeUpdate(data);
        {
        JOptionPane.showMessageDialog(null, "Data berhasil Disimpan");
    }
    }
    catch(Exception e)
    {
        JOptionPane.showMessageDialog(null, "Gagal Insert Data");
    }
}

InsertDaftar Class

public class InsertDaftar implements DaftarInterface {
    public String nama;
    public boolean kuasa;
    Code cd = new Code();

    public void setNama(String nama){
         this.nama=nama;
    }
    public void setKuasa(Boolean kuasa){
         this.kuasa=kuasa;
    }
    public void Akun(){
        String data = "INSERT INTO akun (Nama,Kuasa)"+"values('"+this.nama+"','"+this.kuasa+"')";
        cd.insertData(data);
}

I have created some code boolean for radio button.

    boolean akun_kuasa;
    if (admin.isSelected()){
            akun_kuasa=true;
        }
        if (teller.isSelected()){
            akun_kuasa=false;
        }
    //todo
    InsertDaftar id = new InsertDaftar()
    id.setNama(akun_nama.getText());
    id.setKuasa(akun_kuasa);

there are warning message on

id.setKuasa(akun_kuasa);

Warning in Netbeans.

Initialize variable of akun_kuasa

I have tried to change type of "akun_kuasa" into int, and changed akun_kuasa into 0 and 1, but there still error.

I have searched this problem. but there are to many about BOOLEAN or TinyInt.

NOTE: id is an object that have a method to store into database.

2
  • 1
    What error are you getting? Please add it to your question. Commented Jun 14, 2015 at 2:16
  • What in the world is id.setKuasa(), a class setter? Commented Jun 14, 2015 at 2:29

1 Answer 1

1

akun_kuasa can be undefined after the if's

Set it to false first? Only u would know

It is a good compiler warning to u

akun_kuasa is declared but potentially undefined

when u call the setter

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.