I have doubts regarding the creation of the bank in SQlite on the smartphone via USB. When I run my program in the emulator, the bank works perfectly and smoothly. But I realize that when I do the same, emulating the app on my smartphone, the program does not create the database (which should technically occur). In relation to this, I ask:
- Why is not the smartphone not creating the bank?
- How do I create the bank on my smartphone via USB? What other ways to create the bank on the device?
As requested, the code in one of the tables:
public class BDUserCustomSQLiteOpenHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "MPM_BD.db";
private static final int DATABASE_VERSION = 5;
public static final String TABLE_USUARIO = "MPM_USUARIO";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_NOME = "nome";
public static final String COLUMN_SENHA = "senha";
public static final String COLUMN_PERNR = "pernr";
public static final String COLUMN_CODUSU = "codusu";
public static final String COLUMN_LOGIN = "login";
public BDUserCustomSQLiteOpenHelper (Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase database) {
String DATABASE_CREATE = "create table " + TABLE_USUARIO + " ("
+ COLUMN_ID + " integer not null primary key autoincrement, "
+ COLUMN_NOME + " text, "
+ COLUMN_SENHA + " text, "
+ COLUMN_PERNR + " integer, "
+ COLUMN_CODUSU + " integer, "
+ COLUMN_LOGIN + " text)";
database.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_USUARIO);
onCreate(db);
}
}
BancoDAO:
public class BDUserBancoDao {
private SQLiteDatabase database;
private String[] columns = {BDUserCustomSQLiteOpenHelper.COLUMN_ID, BDUserCustomSQLiteOpenHelper.COLUMN_NOME,
BDUserCustomSQLiteOpenHelper.COLUMN_SENHA, BDUserCustomSQLiteOpenHelper.COLUMN_PERNR,
BDUserCustomSQLiteOpenHelper.COLUMN_CODUSU, BDUserCustomSQLiteOpenHelper.COLUMN_LOGIN};
private BDUserCustomSQLiteOpenHelper sqliteOpenHelper;
public BDUserBancoDao(Context context) {
sqliteOpenHelper = new BDUserCustomSQLiteOpenHelper(context);
}
public void open() throws SQLException {
database = sqliteOpenHelper.getWritableDatabase();
}
public void close() {
sqliteOpenHelper.close();
}
public boolean verificaDados(String codigoUsuario){
long cod = Integer.parseInt(codigoUsuario);
Cursor cursor = database.query(BDUserCustomSQLiteOpenHelper.TABLE_USUARIO, columns, BDUserCustomSQLiteOpenHelper.COLUMN_ID + " = " + cod, null, null, null, null, null);
if((cursor!=null&& cursor.getCount()>0)) return true;
else return false;
}
//Le os dados do usuario e retorna seus valores (id, nome, senha,pernr,codusu,login)
public BDUserGetterSetter lerUsuario(String codigoUsuario) {
long cod = Integer.parseInt(codigoUsuario);
Cursor cursor = database.query(BDUserCustomSQLiteOpenHelper.TABLE_USUARIO, columns, BDUserCustomSQLiteOpenHelper.COLUMN_ID + " = " + cod, null, null, null, null);
BDUserGetterSetter newDadosUser = new BDUserGetterSetter();
cursor.moveToFirst();
newDadosUser.setId(cursor.getInt(0));
newDadosUser.setNome(cursor.getString(1));
newDadosUser.setSenha(cursor.getString(2));
newDadosUser.setPernr(cursor.getString(3));
newDadosUser.setCodusu(cursor.getInt(4));
newDadosUser.setLogin(cursor.getString(5));
cursor.close();
return newDadosUser;
}
public void deletarDados (){
database.delete(sqliteOpenHelper.TABLE_USUARIO,null,null);
}
public String inserirDados(BDUserGetterSetter dadosUser) {
// inserindo valores
ContentValues valores = new ContentValues();
long resultado;
valores.put(sqliteOpenHelper.COLUMN_CODUSU, dadosUser.getCodusu());
valores.put(sqliteOpenHelper.COLUMN_NOME, dadosUser.getNome());
valores.put(sqliteOpenHelper.COLUMN_LOGIN, dadosUser.getLogin());
valores.put(sqliteOpenHelper.COLUMN_SENHA, dadosUser.getSenha());
valores.put(sqliteOpenHelper.COLUMN_PERNR, dadosUser.getPernr());
resultado = database.insert(BDUserCustomSQLiteOpenHelper.TABLE_USUARIO, null, valores);
if (resultado == -1){
return "Erro ao baixar registro";
}else{
return "Registro baixado com sucesso";
}
}
NOTE: I do not know if this helps with anything, but in DMMS, on the smartphone part, the "date" directory is empty.