Popular listview with bank data

0

I have the method that queries the data in the database and a listview above to list this data, but I do not know how to pass the data of the method to the various items so that it is displayed by listview .

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import java.sql.Connection;
import java.sql.Statement;

public class HomeActivity extends AppCompatActivity {

    ConnectionClass connectionClass;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        connectionClass = new ConnectionClass();

        // Arrray de dados, que serão exibidos na ListView...
        String[] items = {/*DADOS DO BANCO*/};

        // Inicializando o adapter...
        ArrayAdapter<String> itemsAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);

        ListView listview = findViewById(R.id.lista);

        listview.setAdapter(itemsAdapter);

    }

    public void buscarDados(){

        //Traz dados do MainActivity
        Intent it = getIntent();
        String userid = it.getStringExtra("Id");

        try{
            Connection con = connectionClass.CONN();
            if (con == null) {
                Toast.makeText(getApplicationContext(),"Error in connection with SQL server", Toast.LENGTH_SHORT).show();
            } else {
                String query = "SELECT * FROM ESP353IntraUsu where DsLogin='" + userid + "'";
                Statement stmt = con.createStatement();
                stmt.executeQuery(query);
            }
        } catch (Exception ex) {
            Toast.makeText(getApplicationContext(),"Error", Toast.LENGTH_SHORT).show();
        }
    }

}
    
asked by anonymous 29.06.2018 / 19:10

0 answers