Creating more than one Android Studio table (SQLite)

1

I'm trying to develop a mobile application for a final job in my college, it's quite simple!

The application has to save the information registered in the database.

But I would have to create 4 different tables to store the data, the tables would be: Usuário , Aplicativo , Empresa and Funcionários .

And after registering, make Selects that the teacher wants.

The problem: I do not know if it is possible to make this creation of 4 different tables in Android Studio and then insert data in them to make the selects.

I have previously done an application similar to this, but only used 1 table.

    
asked by anonymous 05.12.2016 / 20:35

2 answers

1

If I understand, you want to create the table and already enter the values?

You can perform as many operations as you need in onCreate .

Here's an example:

@Override
public void onCreate(final SQLiteDatabase db) {

    //Vamos criar as tabelas... 
    db.execSQL("CREATE TABLE Usuario ( id INTEGER PRIMARY KEY, nome TEXT )");
    db.execSQL("CREATE TABLE Aplicativo ( id INTEGER PRIMARY KEY, nome TEXT )");
    //Seus demais INSERTS...

    /**
     * Agora vamos inserir os dados na tabela...
     **/

    db.execSQL("INSERT INTO Usuario values (1, 'Usuario Um')");
    db.execSQL("INSERT INTO Usuario values (2, 'Usuario Dois')");
    db.execSQL("INSERT INTO Usuario values (3, 'Usuario Tres')");
    db.execSQL("INSERT INTO Usuario values (4, 'Usuario Qautro')");
}
    
05.12.2016 / 21:08
0

Friend, using database to persist data is very common, and for this you have some alternatives.

  • You can build an API, which you query, and insert data. Using a server, with the language you want. Communicating via JSON.
  • If you do not have a certain need for communication between other devices, and want to persist this data locally on the device you can use some platform. I personally like DB Flow or even implement it "on hand" with the SQLiteOpenHelper library. DEVMEDIA Tutorial
  • 05.12.2016 / 21:09