2
Good afternoon, I need to do a query but I can’t use the cursor.
Example I have an object that I created that is called Databasehelper, within it I created some methods (prepare,bindParam,getQuery,execute), but in execute I need the return to be a Jsonarray or an array as is done in PHP with mysql. Dry down an example of what I’m trying to do. I have this need because the query will be executed via Javascript in a Czech application, but I cannot use the cursor.
@JavascriptInterface
public JSONObject execute() throws JSONException{
String sql = this.sql_prepare;
JSONObject retorno = new JSONObject();
try
{
SQLiteDatabase db = this.getReadableDatabase();
db.execSQL(sql);
retorno.put("ok", true);
retorno.put("return", "Aqui deve conter um objeto array para que eu possa trabalhar com o javascript e esse objeto deve conter todo o retorno do execSQL");
return retorno;
} catch(Exception e){
AlertDialog.Builder erro = new AlertDialog.Builder(contexto);
erro.setTitle("Erro de SQL");
erro.setMessage("Ocorreu um erro na execução de sua query.\nQuery: "+sql+"\nErro:"+e.getMessage());
erro.setPositiveButton("OK", null);
erro.show();
retorno.put("ok", false);
retorno.put("return", e.getMessage().toString());
return retorno;
}
}
Sorry I didn’t understand the comic-book part
– Hiago Souza
@Hiagosouza A method any of yours where effectively queries the database and returns to that example code a
ArrayList
with the selected data.– Zuul
So more my question was exactly this, as I take the return of a select and turn it into an arraylist to put in jsonobject.
– Hiago Souza
@Hiagosouza I have completed the answer with an example for this case of generating a
arrayList
from the database query.– Zuul
Thank you, now I can continue ;)
– Hiago Souza