安卓原生数据库语句踩过的小坑

2018-08-11  本文已影响0人  dev晴天
Demo 
            case R.id.btn_find:
                StringBuilder sb =new StringBuilder();
               Cursor cursor= db.rawQuery("select name,number from student",null);
                // Couldn't read row 0, col 2 from CursorWindow.
                //  Make sure the Cursor is initialized correctly before accessing data from it.
                Log.i("数据行数", "onClick: "+cursor.getCount());
                if (cursor!=null&&cursor.getCount()>0){
                   while(cursor.moveToNext()){
                       name = cursor.getString(0);
                       number= cursor.getString(1);
                       sb.append("name"+name+" "+"number"+number+"\n");
                   }
               }
                cursor.close();
                tvShow.setText(sb.toString());
                break;

在查询的时候
查询出来的是新表
sql逻辑是,查询结果作为结果表,是一个新表
也就是结果表的col只有两列

故用0 1  之前表中三列 总以为查询 2 3(getString(1),getString(2)) 就有结果实际错了

上一篇下一篇

猜你喜欢

热点阅读