How to use Select

Asked

Viewed 58 times

0

I was able to save information in my Sqlite bank, only I can’t call them.

I’m trying to use the following method:

private void verPessoas() {
    ArrayList<RespostasAguaCasa> pessoas = new Read().getLista();
    for (int i = 0; i < pessoas.size(); i++) {
        RespostasAguaCasa p = pessoas.get(i);
        int a = p.getValoragua();
        impri.setText("+"+ a);
    }

    if (pessoas.size() == 0) System.out.println("# Não existe valor .");
}

READ

      public class Read {
            public ArrayList<RespostasAguaCasa> getLista() {
            SQLiteDatabase db = 
          Maindb.getInstancia().getWritableDatabase();
            String query = "SELECT * FROM " + Maindb.TABELA;
            ArrayList<RespostasAguaCasa> lista = new ArrayList<>();

            Cursor c = db.rawQuery(query, null);
            if (c.moveToFirst()) {

                do {
                    RespostasAguaCasa resp = new 
                   RespostasAguaCasa(c.getString(0));
                    resp.setId(c.getInt(1));
                    resp.setValoragua(c.getInt(2));
                    resp.setAcordarhora(c.getInt(3));
                    resp.setAcordarminu(c.getInt(4));
                    resp.setDormirhora(c.getInt(5));
                    resp.setDormirminu(c.getInt(6));
                    lista.add(resp);
                }
                while (c.moveToNext());
                {
                }


    }
    c.close();
    return lista;
}

}

1 answer

2

1 - It is necessary to start the People Table with a value?

In the case of ( Person person = new Person(c.getString(0)); ) we leave an empty constructor for the Table, so that we can call it:

Pessoa pessoa = new Pessoa();
pessoa.setNome("nome");

2 - Call the results by the columns:

pessoa.setNome(c.getString(c.getColumnIndex(Coluna_Nome)));

3 - In the case of ( person.setDeficiency(c.getInt(4) == 1); ) something like:

Int valor_temporario = 0;
if(c.getInt(c.getColumnIndex(Tabela_Deficiencia)) == 1){
valor_temporario = 1;
}else{
valor_temporario = 0;
}
pessoa.setDeficiencia(valor_temporario);

De Resto seems OK, in case it’s nothing of the kind, I would need more information.

  • I’m having trouble calling the c

  • I had got the Read of the wrong project if it can help me with the right I edited the question

Browser other questions tagged

You are not signed in. Login or sign up in order to post.