Java 为什么android studio中的for循环在第一次迭代后停止?

Java 为什么android studio中的for循环在第一次迭代后停止?,java,android-studio,for-loop,jdbc,android-asynctask,Java,Android Studio,For Loop,Jdbc,Android Asynctask,我创建了一个系统,在这个系统中,我可以在androidstudio中只使用一个异步任务类来运行所有postgresql查询。这真的(!!)具有挑战性,因为我必须面对大量的限制。但这真的很棒 //Used for connecting to database and executing queries. //Index 0 of input string must be the query, Index 1 must be the tablename we demand //We can only

我创建了一个系统,在这个系统中,我可以在androidstudio中只使用一个异步任务类来运行所有postgresql查询。这真的(!!)具有挑战性,因为我必须面对大量的限制。但这真的很棒

//Used for connecting to database and executing queries.
//Index 0 of input string must be the query, Index 1 must be the tablename we demand
//We can only gather data from 1 table for each query, so if you need data from several tablecolumns, use multiple queries like:
//[0] = query, [1] = tablename, [2] = 2nd query, [3] = 2nd tablename, [4] = 3rd query, [5] = 3rd table name ... and so on (each query must come with a tablename)
public class DBHandler extends AsyncTask<String, Void, List<String>>
{
public AsyncResponse delegate;

@Override
protected List<String> doInBackground(String...query)
{
    List<String> result = new ArrayList<String>();
    String sql;
    String tableresult = null;
    Connection conn = null;
    Statement st = null;
    ResultSet rs = null;

    try {
        Class.forName("org.postgresql.Driver");
        conn = DriverManager.getConnection("jdbc:postgresql://192.168.200.300:5439/dbname?user=anonymous&password=secretpw");
        st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); //necessary if you want to use rs.first() after rs.next(), it makes the resultset scrollable

        for (int i = 0; i <= query.length-1; i = i+2) //queries are always stored in i=0 and/or in i+2, because i+1 contain the demanded tablenames for resultset handling
        {
            System.out.println("I is: " +i);
            if (!query[i].isEmpty())
            {
                System.out.println(query[i]);
                sql = query[i];
                rs = st.executeQuery(sql);

                while (rs.next())
                    if (!query[i + 1].isEmpty() || !rs.getString(query[i + 1]).isEmpty()) //if i+1 is empty, there is no demanded tablename. Used when we dont need any return values (ie. INSERT, UPDATE)
                    result.add(rs.getString(query[i + 1])); //demanded tablename is always stored in i+1

                //We add an empty entry if we demand multiple tablenames so we can keep them seperate
                //Might be replaced with any other char, but you will have to backtrack all usages of DBHandler and fix the filters there
                if(i+2 < query.length)
                result.add(" ");
            }
            rs.first(); //reset pointer for rs.next()
        }

        rs.close();
        st.close();
        conn.close();
        System.out.println("End of AsyncTask");
    }

    catch (SQLException ex)
    {
        ex.printStackTrace();
    }

    catch (Exception e)
    {
        e.printStackTrace();
    }
    return result;
}

//onPostExecute returns query result in a List.
//We need to use interaces delegate feature to send the result to other classes, like "Auslieferung", which is implementing the interface
@Override
protected void onPostExecute(List<String> result)
{
    super.onPostExecute(result);
    System.out.println("Result: " +result.toString());
    if (!result.isEmpty())
        delegate.processFinish(result);
}
}

为什么这个for循环在第一次运行后立即停止运行?调试器没有显示任何异常,所有内容都已正确解析,并且没有缺少任何查询。更新表不会返回任何结果,但此处的任何结果都不依赖于结果值。我试图在一个字符串变量中运行20个更新查询,但是for循环在第一次迭代后停止。调试器或日志中不会显示任何问题。我有没有监督过什么,或者有什么我不知道的?这可能是一个错误吗?请帮帮我!这个问题让我发疯。

也不例外?不确定如果使用更新调用
executeQuery
会发生什么情况,该更新不会返回单个结果集(Doc:“SQLException…给定的SQL语句会生成除单个ResultSet对象以外的任何内容…”不,就我所见,没有异常。当我回到办公室时,我会把日志发出去@Carlos Heuberger:好吧,我仔细看了一下。有一个W/IInputConnectionWrapper:finishComposingText在非活动InputConnection上W/System.err:org.postgresql.util.PSQLException:查询不返回任何结果(无异常?不确定如果调用带有更新的
executeQuery
会发生什么,该更新不会返回单个结果集(文档:“SQLException…给定的SQL语句生成除单个ResultSet对象以外的任何对象…”不,据我所知,没有例外。当我回到办公室时,我会发布日志@Carlos Heuberger:好的,我仔细看了一下。有一个W/IIInputConnectionWrapper:finishComposingText on inactive InputConnection W/System.err:org.postgresql.util.PSQLException:查询不返回任何结果(
for (int i = 0; i <= query.length-1; i = i+2)
String updatequeries[] = {UPDATE delivery SET contactperson = 'Jon Doe' WHERE officeid = 5, " ", UPDATE delivery SET contactemail = 'abd@def.gh' WHERE officeid = 5, " "};