user3728517 user3728517 - 1 year ago 58
Java Question

How to access preexcute data in doinbackground?

I fetch a database and display value in a spinner in preexcute doinbackground thread i want to insert that spinner value in a sqlite table,I know that i can not use ui component in doinbackground. Expecting your help.
Here are my preexcute value

try {
statement = connect.prepareStatement("exec dbo.getSalesIdtest;");
} catch (SQLException e) {
Log.e("Error 1 here: ", e.getMessage());

try {
rs = statement.executeQuery();
} catch (SQLException ex) {
Log.e("error 2 here: ", ex.getMessage());
try {
while( {
TextView generateData = (TextView) findViewById(;
pab = rs.getString("CurrentNo");
Log.e(pab,"Message here is");
boolean isInserted = orderDB.insertorderData(rs.getString("CurrentNo"));

if (isInserted == true)
Toast.makeText(orderChalan.this, "Data save successfully", Toast.LENGTH_LONG).show();
Toast.makeText(orderChalan.this, "Data not Inserted", Toast.LENGTH_LONG).show();

and here is code in my doinbackground

if (con == null) {
z = "Check Your Internet Access!";
} else {
String query = "insert into dbo.slsOrderD(osdSalesID,osdProductID,osdQty)values('joy','" + getRata.getString(1).toString() + "','" + getRata.getString(2).toString() + "');";
PreparedStatement preparedStatement = con.prepareStatement(query);
z = "New client's data added successfully";
isSuccess = true;
} catch (Exception ex) {
isSuccess = false;
z = "Exceptions";
Log.e("ERRO", ex.getMessage());

In insert statement i have to access data from pre execute spinner element how to solve this issue?

Answer Source

If you declare variables that you are updating in your onPreExecute() as class members of your inherited version of Asynctask, then you should be able to access them from the doInBackground().

From what I see you are declaring them as local variables in OnPreExecute()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download