我在preexcute value.in doinbackground线程中获取数据库并在微调器中显示值我想在sqlite表中插入该微调器值,我知道我不能在doinbackground中使用ui组件。期待你的帮助。 这是我的预先执行值
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(rs.next()) {
TextView generateData = (TextView) findViewById(R.id.getOrderid);
pab = rs.getString("CurrentNo");
generateData.setText(pab);
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();
else
Toast.makeText(orderChalan.this, "Data not Inserted", Toast.LENGTH_LONG).show();
这是我的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);
preparedStatement.executeUpdate();
z = "New client's data added successfully";
isSuccess = true;
}
} catch (Exception ex) {
isSuccess = false;
z = "Exceptions";
Log.e("ERRO", ex.getMessage());
}
在insert语句中我必须从pre execute spinner元素访问数据如何解决这个问题?
答案 0 :(得分:1)
如果您将 onPreExecute()中正在更新的变量声明为继承的Asynctask版本的类成员,那么您应该可以从 doInBackground()
从我看到你在 OnPreExecute()
中将它们声明为局部变量