I have the following scenario: in my application I am using AsyncTask A to connect to the database and check the login. This AsyncTask's doInBackground method returns a boolean value. For some user interaction I am using AsyncTask B to connect to the same database and get back a ResultSet. Everything is working fine, but I want to use only one AsyncTask. How can I do this?
AsyncTask A code
@Override
protected Boolean doInBackground(String... arg0) {
String username = arg0[0];
String password = arg0[1];
Boolean v = false;
ResultSet rs = null;
Statement stmt = null;
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
conn = DriverManager.getConnection(jdbcURL, user, passwd);
try {
stmt = conn.createStatement();
try {
rs = stmt
.executeQuery("execute"
+ username + "'");
if (rs.next()) {
String p=rs.getString("pass_word");
if (p==null){
if(password.equals(""))
v = true;}
else
if(p.equals(password))
v=true;
}
} finally {
try {
rs.close();
} catch (Throwable ignore) {
}
}
} finally {
try {
stmt.close();
} catch (Throwable ignore) {
}
}
} catch (java.sql.SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (java.lang.ClassCastException e) {
e.printStackTrace();
}
return v;
}
AsyncTask B code
@Override
protected ResultSet doInBackground(String... params) {
Statement stmt = null;
ResultSet rs = null;
try {
if (conn == null) {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
conn = DriverManager.getConnection(jdbcURL, user, passwd);
}
stmt = conn.createStatement();
rs = stmt.executeQuery(params[0]);
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}