游标获取零值

时间:2018-07-30 08:17:40

标签: android arrays sqlite

当使用游标从内部联接表中获取值时,游标获取零值时出现问题。你能告诉我程序有什么问题吗?

这是我的程序:

private JSONArray getResults()
{
    Context context = this;

    String myPath = String.valueOf(context.getDatabasePath("ekantin1.db"));// Set path to your database

    //String myTable = DatabaseHelper.ORDER_TABLE_NAME;//Set name of your table

    SQLiteDatabase myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

    Cursor cursor = myDataBase.rawQuery( "SELECT  * FROM " + DatabaseHelper.LINEITEMS_TABLE_NAME + " INNER JOIN " + DatabaseHelper.ORDER_TABLE_NAME
            + " ON " + DatabaseHelper.COL6 + " = " + DatabaseHelper.COL_1, null );

    JSONArray resultSet     = new JSONArray();

    cursor.moveToFirst();
    while (cursor.isAfterLast() == false) {

        int totalColumn = cursor.getColumnCount();
        JSONObject rowObject = new JSONObject();

        for( int i=0 ;  i< totalColumn ; i++ )
        {
            if( cursor.getColumnName(i) != null )
            {
                try
                {
                    if( cursor.getString(i) != null )
                    {
                        Log.d("TAG_NAME", cursor.getString(i) );
                        rowObject.put(cursor.getColumnName(i) ,  cursor.getString(i) );
                    }
                    else
                    {
                        rowObject.put( cursor.getColumnName(i) ,  "" );
                    }
                }
                catch( Exception e )
                {
                    Log.d("TAG_NAME", e.getMessage()  );
                }
            }
        }
        resultSet.put(rowObject);
        cursor.moveToNext();
    }
    cursor.close();
    db.close();
    Log.d("TAG_NAME", resultSet.toString() );


    Intent pass_data = new Intent(this,BluetoothOut.class);

    pass_data.putExtra("pindah",resultSet.toString());
    startActivity(pass_data);

    return resultSet;
}

这是日志猫:

  

07-30 14:42:21.928 8386-8386 / com.example.windows8.ekantin D / TAG_NAME:   []数据库的SQLiteConnection对象   '/data/data/com.example.windows8.ekantin/databases/ekantin1.db'是   泄漏!请修复您的应用程序以结束正在进行的交易   正确并在不再需要它时关闭数据库。

感谢您的帮助。

0 个答案:

没有答案