结果集.next()显示部分结果-与跳过第一行无关

时间:2018-12-28 02:35:01

标签: android sql jtds

我正在创建一个使用SQL数据的android应用。当我在主要活动中运行(CODE1)时,将检索所有行(10行)。当我将代码作为onPOstExecute方法(CODE2)的一部分放置在AsyncTask类中时,仅显示前四行。例外是在第四行之后显示空行。

CODE1

if (con == null) {
        zES = "Error in connection with SQL server";
    } else {

        String queryFE = "SELECT * FROM executed_steps where Batch_No ='" + rBatch_No + "'";

        try {

            PreparedStatement ps = con.prepareStatement(queryFE);
            result_rs_ES = ps.executeQuery();

        } catch (Exception ex) {
            result_rs_ES = null;
        }
    }

    if (result_rs_ES == null) {
        Toast.makeText(getApplication(), "No Batch Found"+zES, Toast.LENGTH_SHORT).show();
    } else {

        try {
            while (result_rs_ES.next()) {

                rStep_Id = result_rs_ES.getString("Step_Id");
            }
        } catch (Exception e) {

}

CODE2 这是AsyncTask

private class FindExecutedStepsAsyncTask extends AsyncTask<String,Void,ResultSet > {

    String result_ES,zES;
    ResultSet result_rs_ES;

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected ResultSet doInBackground(String... params) {


        zES=params[0];
        Connection con = connectionClass.CONN();

        if (con == null) {
            zES = "Error in connection with SQL server";
        } else {

            String queryFE = "SELECT * FROM executed_steps where Batch_No ='"+zES+"'";

            try {

                PreparedStatement ps = con.prepareStatement(queryFE);
                result_rs_ES = ps.executeQuery();

            } catch (Exception ex) {
                result_rs_ES=null;
            }
        }
        return result_rs_ES;
    }

    @Override
    protected void onPostExecute(ResultSet mresult_rs_ES) {
        passdatasteps(mresult_rs_ES);
    }
}

private void passdatasteps(ResultSet mresult_rs_ES) {

    if (mresult_rs_ES == null) {
        Toast.makeText(getApplication(), "No Batch Found", Toast.LENGTH_LONG).show();
    } else {

        try {
            while (mresult_rs_ES.next()) {


                rStep_Id = mresult_rs_ES.getString("Step_Id")
            }
        }
        catch (Exception e) {
        }
}

0 个答案:

没有答案