java - Multiple tables in a DB SQLite -


i working 1 table , program ok, have add table database, , logic code :

package net.shamanoperativo;  import android.content.context; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqlitedatabase.cursorfactory; import android.database.sqlite.sqliteopenhelper;  public class usuariossqlitehelper extends sqliteopenhelper {      //sentencia sql para crear la tabla de incidentes     string sqlcreate = "create table incidentes  ( idinterno integer primary key  , codreg text, codgr text, entidad text, codinc text, loc text, dom text, sint text, movil text, sexo text, edad integer, estado text, latitud double, longitud double,colorloc text, colorgr text )";     string sqlcreate2 = "create table moviles (idinterno integer primary key, nummovil text, colmovil text, estado text, localidad text, cantserv integer)";     string sqlcreateindex = "create unique index idxidinterno on incidentes(idinterno)";      public usuariossqlitehelper(context contexto, string nombre,                                cursorfactory factory, int version) {         super(contexto, nombre, factory, version);       }      @override     public void oncreate(sqlitedatabase db) {         //se ejecuta la sentencia sql de creación de la tabla         db.execsql(sqlcreate);         db.execsql(sqlcreateindex);         db.execsql(sqlcreate2);         }      @override     public void onupgrade(sqlitedatabase db, int versionanterior, int versionnueva) {          //se elimina la versión anterior de la tabla         db.execsql("drop table if exists incidentes");         db.execsql("drop table if exists moviles");           //se crea la nueva versión de la tabla         db.execsql(sqlcreate);         db.execsql(sqlcreate2);      } } 

my table incidentes ok, using always.. can't use table moviles, use table here:

 usuariossqlitehelper usdbh =                 new usuariossqlitehelper(this, "dbincidentes", null, 1);              sqlitedatabase db = usdbh.getwritabledatabase();         //abro base de datos para escritura              if(db != null)             {                   //db.execsql("delete moviles");                  (int i=0; i<= (vectotal.length) -1; i++) {                    string reg = vectotal[i].tostring();                  string [] inc = textutils.split(reg, "\\^");                     string nummovil = inc[0];                 string colmovil = inc[1];                 string estado = inc[2];                 string localidad = inc[3];                 string strcantserv = inc[4];                  integer cantserv = integer.parseint(strcantserv);                    try{                                      //insertamos los datos en la tabla incidentes  db.execsql("insert moviles ( idinterno, nummovil, colmovil, estado, localidad, cantserv) " +              "values ("+(i+1)+", '" + nummovil +"', '" + colmovil +"' , '" + estado +"', '" + localidad +"', " +cantserv +" )");    }  catch (exception e)  {     e.getmessage();   } 

is there thing have handle 2 tables or more? isn't same adapter , refering table of database want consult or add info?

when program want add info moviles, logcat says can't because moviles doesn't exist.

no, there isn't need handling more 1 table.

i think table not created because neither oncreate() (because database exists) noronupdate() (you never increased database version pass usuariossqlitehelper, right?) called.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -