Hello, I'm creating a search project and need to make a commit in my database.
I have an "establishments" table in my SQLite database, with the following columns: id, name and category . And a String variable named " nameStab "
I need to make a comparison between the value of the variable and the data of the database, that is, I need to check if there is any field inside the name column that has the same variable value, return a True for example, otherwise, return a False.
Follow the codes ..
SQL Code
SQLiteDatabase db = openOrCreateDatabase("pesquisa.db", Context.MODE_PRIVATE, null);
StringBuilder sqlEstabelicimento = new StringBuilder();
sqlEstabelicimento.append("CREATE TABLE IF NOT EXISTS [estabelecimentos](");
sqlEstabelicimento.append("[_id] INTEGER PRIMARY KEY AUTOINCREMENT, ");
sqlEstabelicimento.append("nm_estab VARCHAR(100), ");
sqlEstabelicimento.append("categoria VARCHAR(50));");
db.execSQL(sqlEstabelicimento.toString());
Java code
public void pesquisar(View view){
SQLiteDatabase db = openOrCreateDatabase("pesquisa.db", Context.MODE_PRIVATE, null);
EditText nomeDigitado = (EditText) findViewById(R.id.txt_NomePesquisa);
String texto = nomeDigitado.getText().toString();
try{
db.execSQL("SELECT nm_estab FROM estabelecimentos WHERE nm_estab = '"+texto+"'");
}
catch (Exception erro){
}
}