MySQL error store boolean value into tinyint

790 Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

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