I'm trying to connect my app in android directly with the bank that is on a server. I made the connection in an AsyncTask, follow the code.
public class ConnectionTask extends AsyncTask<Object, Object, Connection> {
private final Context context;
private final String endereco = "jdbc:postgres://192.168.1.36/sics";
private final String usuario = "postgres";
private final String senha = "postdba";
private ProgressDialog progress;
public ConnectionTask(Context context) {
this.context = context;
}
@Override
protected void onPreExecute() {
progress = ProgressDialog.show(context, "Aguarde...",
"Tentando realizar conexão com o banco de dados!", true, true);
}
@Override
protected Connection doInBackground(Object... params) {
Connection conn = null;
try {
Class.forName("org.postgresql.Driver").newInstance();
conn = DriverManager.getConnection(endereco, usuario, senha);
} catch (Exception e) {
Log.i("CONEXAO", "NAO CONECTADO " + e.getMessage());
}
return conn;
}
@Override
protected void onPostExecute(Connection result) {
progress.dismiss();
}
}
So far everything is without error, but the error in my DAO. Here is my method list below.
public List<Categoria> listarCategoria(Context context) {
List<Categoria> lista = new ArrayList<Categoria>();
/*Cursor c = helper.getReadableDatabase().rawQuery(
"select * from categorias", null);
while (c.moveToNext()) {
Categoria categoria = fill(c);
lista.add(categoria);
}
return lista;*/
Connection conn = new ConnectionTask(context).execute();
PreparedStatement stmt = conn.prepareStatement("select * form categoria");
return lista;
}
You're giving the line error
Connection conn = new ConnectionTask(context).execute();
Follow a print with the error
Thank you in advance! :)