0
In my database I have a table State and Cities, I would like to enter this data once the app is installed, ie when creating the database these records are already inserted in the tables at once. I did the following code but is only entering the first state
public class BancoDados extends SQLiteOpenHelper {
public static final String NOME_BANCO = "carona";
private static final int VERSAO_BANCO = 1;
public BancoDados(Context context) {
super(context, NOME_BANCO, null, VERSAO_BANCO);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(SQL_ESTADO);
db.execSQL(SQL_LISTA_ESTADOS);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
String SQL_ESTADO = "CREATE TABLE [Estado](\n" +
"[EstadoId] [INT] NOT NULL,\n" +
"[Sigla] [char](2) NOT NULL,\n" +
"CONSTRAINT [PK_Estado] PRIMARY KEY ([EstadoId])\n" +
");";
String SQL_LISTA_ESTADOS = "INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (1,'AC');\n"+
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (2,'AL'); " +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (3,'AM'); " +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (4,'AP'); " +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (5,'BA'); " +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (6,'CE'); " +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (7,'DF'); " +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (8,'ES'); " +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (9,'GO'); +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (10,'MA');" +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (11,'MG');" +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (12,'MS');" +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (13,'MT');" +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (14,'PA');" +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (15,'PB');" +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (16,'PE');" +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (17,'PI');" +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (18,'PR');" +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (19,'RJ');" +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (20,'RN');" +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (21,'RO');" +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (22,'RR');" +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (23,'RS');" +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (24,'SC');" +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (25,'SE');" +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (26,'SP');" +
"INSERT INTO [Estado] ([EstadoId],[Sigla]) VALUES (27,'TO');";
}
There is a quotation mark missing at the end of the line that inserts record 9. It turns around anyway?
– Márcio Oliveira
Unfortunately it is not. I have removed up to the n in record 1. It still keeps entering only the first state. This running however just inserts the first.
– alannrs