Display query data in a toast

1

I want to show the query data in a Toast and do not do it, this is my code:

    conn3 = DBConnection3.getInstance().getConnection();
    try {
        String stsql="Select a.idOperario,b.IdLlamada,b.Fecha,b.Mensaje,b.De,b. IdUsuarioDestino,b.Estado,b.IdUsuarioCrea from xTRAINING.dbo.tbUsuarioOperario a INNER JOIN WorkFlow.dbo.Llamadas b ON a.idOperario=b.IdUsuarioCrea where Estado=0 and CUsuario='"+t1+"'ORDER BY IdLlamada asc";
        Statement st = conn3.createStatement();
        ResultSet rs = st.executeQuery(stsql);
        while (rs.next()) {
            IdLlamada = rs.getInt(1);
            Fecha = rs.getDate(2);
            Mensaje = rs.getString(3);
            De = rs.getString(4);
            IdUsuarioDestino = rs.getString(5);
            Estado =rs.getBoolean(6);
            IdUsuarioCrea=rs.getString(7);
            IdOperario=rs.getString(8);
            Cusuario=rs.getString(9);

            consulta5 = "IdLlamada" + rs.getInt(1) + " Fecha " + rs.getDate(2) + " Mensaje " + rs.getString(3) + " De " + rs.getString(4) + " IdUsuarioDestino " + rs.getString(5) + "Estado" + rs.getBoolean(6)+" IdUsuarioCrea " + rs.getString(7)+" IdOperario " + rs.getString(8)+ " CUsuario " + rs.getString(9);
            System.out.println("IdLlamadas.getInt(1) + " Fecha " + rs.getDate(2) + " Mensaje " + rs.getString(3) + " De " + rs.getString(4) + " IdUsuarioDestino " + rs.getString(5) + "Estado" + rs.getBoolean(6)+" IdUsuarioCrea " + rs.getString(7)+" IdOperario " + rs.getString(8)+ " CUsuario " + rs.getString(9));
        }

    } catch (SQLException e1) {
        e1.printStackTrace();
    }
    Toast.makeText(Main2Activity.this, "registro de llamadas perdidas", Toast.LENGTH_SHORT).show();
}
Toast.makeText(Main2Activity.this,consulta5,Toast. LENGTH_LONG).show();

I have the error in the getText() of the query:

 String stsql="Select a.idOperario,b.IdLlamada,b.Fecha,b.Mensaje,b.De,b.IdUsuarioD‌​estino,b.Estado,b.Id‌​UsuarioCrea from xTRAINING.dbo.tbUsuarioOperario a INNER JOIN WorkFlow.dbo.Llamadas b ON a.idOperario=b.IdUsuarioCrea where Estado=0 and CUsuario='"+t1.getText()+"'ORDER BY IdLlamada asc";

How do I fix it? Any solution?

    
asked by TAMARUSS 15.11.2016 в 09:27
source

1 answer

1

You must use the toString() method to correctly get the value entered within EditText .

t1.getText().toString();

otherwise you are not getting the value within the EditText, you probably get something similar to:

android.widget.EditText@12345ff0

Assuming that within your EditText t1 you are typing the user name correctly , use the .toString() method and this way your query will be correctly constructed (also add a space in ' ORDER ) since you will get the value that is contained within EditText :

String stsql="Select a.idOperario,b.IdLlamada,b.Fecha,b.Mensaje,b.De,b.IdUsuarioD‌​estino,b.Estado,b.Id‌​UsuarioCrea from xTRAINING.dbo.tbUsuarioOperario a INNER JOIN WorkFlow.dbo.Llamadas b ON a.idOperario=b.IdUsuarioCrea where Estado=0 and CUsuario='"+t1.getText().toString()+"' ORDER BY IdLlamada asc";
    
answered by 15.11.2016 в 18:38