Fill Spinner with SQL

0

I am trying to fill a spinner through a query of SQLServer, I put you in situation.

I am making a form from which I bring data from my database and I put them in EditText or TextView, until then everything is fine. I find now that fill a spinner with the option that the user has (in the table I have 4 but only 1 is for each "person", that this is reflected in the database) in the database is not so easy. I leave a bit of code for you to try to help me, thank you!

 Connection cn = consql.conexionBD();
    String sel = " SELECT INC.idIncidencia,INC.numIncidencia,INC.numParte,CLI.NombreComercial,INC.fechaTrabajo,INC.incidencia,INC.trabajo,INC.OBSERVACIONES,UB.telefono1,UB.telefono2,IMOD.modo,PER.Nombre,UB.direccion,POB.poblacion  from incidencias as INC.

I use the DB connection function () of my other class where I only have the SQL connection. My query to the database, which in SQL returns me perfectly and all correct, one tables because I have the information in different.

 try {
        Statement pst = cn.createStatement();
        //Ejecuta el query del SQL
        ResultSet rs = pst.executeQuery(sel);
        //Recorre la tabla del SQL
        while (rs.next()) {
            //Hacer consulta principal en String sel y despues aquí asignar su columna en el textview o editText que necesite.
            //tvNumIncidencia.setText(rs.getString(2));
            tvNParte.setText(rs.getString(3));
            tvNombreComercial.setText(rs.getString(4));
            etDate.setText(rs.getString(5));
            tvIncidencia.setText(rs.getString(6));
            tvTrabajo.setText(rs.getString(7));
            tvObservaciones.setText(rs.getString(8));
            tvTlf1.setText(rs.getString(9));
            tvTlf2.setText(rs.getString(10));
            ***spinnerModo.(rs.getString(11));***
            tvDireccion.setText(rs.getString(13));
            tvPoblacion.setText(rs.getString(14));

            if(tvTlf1.getText().toString().trim().isEmpty()){
                tvTlf1.setText("0");
            }else{
            }
            if(tvTlf2.getText().toString().trim().isEmpty()){
                tvTlf2.setText("0");
            }else{
            }
        }

        if (rs != null) {
        } else
            Toast.makeText(getApplicationContext(),
                    "No hay nada ", Toast.LENGTH_LONG).show();
        if (rs != null)
            rs.close();

    } catch (SQLException e) {
        Log.i("Error", "Error al abrir o crear la base de datos" + e);
    }
}

Then I use a try cath to read the records of the SQL tables, and as you can see I collect the data in different TextView and some EditText, here comes the problem. I can not use the setText (rs.getString (column name)) in the spinner obviously, but I do not know how to fill the spinner then, what should I do? Greetings, thanks in advance!

    
asked by Borja Ibañez Melero 16.05.2018 в 10:12
source

0 answers