How can I send a complete sqlite table to mysql in android studio?

1

I need to send all the information from my table:

String create_aguacate_table = "CREATE TABLE " + TABLE_AGUACATE + " (" + COLUMN_IDAGUACATE + " INTEGER PRIMARY KEY, " + COLUMN_CALIBREAGUACATE + " TEXT, "+ COLUMN_PRECIOAGUACATE + " TEXT, " + COLUMN_PORCENTAJEAGUACATE + " TEXT, " + COLUMN_RESULTADOAGUACATE + " TEXT)";
        db.execSQL(create_aguacate_table);

How can I send all the data?

    
asked by DoubleM 11.12.2016 в 05:36
source

1 answer

0

The first thing you should keep in mind is that your table has a photmato, so to be ordered you should create a class with the same attributes.

public class TuClase {
       int id;
       String nombre;
}

This is an example but you know the fields you require. Once you have this class and its constructor methods and their get and set you make a ArrayList of type TuClase .

ArrayList<TuClase> lista = new ArrayList<TuClase>();
if (cursor .moveToFirst()) {
    while (cursor.isAfterLast() == false) {
        int id = cursor.getInt(cursor.getColumnIndex(id));
        String nombre = cursor.getString(cursor.getColumnIndex(nombre));
        TuClase objeto = new Objeto(id,nombre);
        list.add(objeto);
        cursor.moveToNext();
    }
 }

So you get all the records and you have them in a list, having this list you can send it to your server depending on how you receive it, the best would be a json.

JSONArray jsonArrayMiLista = new JSONArray(lista);
    
answered by 11.12.2016 / 17:35
source