码迷,mamicode.com
首页 > 移动开发 > 详细

android获取数据库查询的结果

时间:2020-03-08 13:49:17      阅读:85      评论:0      收藏:0      [点我收藏+]

标签:roi   崩溃   输出   one   help   length   over   cccccc   query   

参考:https://www.xuebuyuan.com/3244495.html

原来错误的程序,app会崩溃(请大神指点错误的原因是啥?_(:з)∠)_)

 1 btn_search.setOnClickListener(new View.OnClickListener() {
 2             @Override
 3             public void onClick(View v) {
 4                 String key = et_username.getText().toString();
 5                 Cursor cursor = dbOpenHelper.getReadableDatabase().query("tb_user",null,"username=?",new String[]{key}, null,null,null);
 6 
 7                 if (cursor.getCount() == 0) {
 8                     Toast.makeText(MainActivity.this,"很遗憾,没有相关记录",Toast.LENGTH_SHORT).show();
 9                 } else {
10 //                    while (cursor.moveToNext()) {
11 //                        Log.i("cccccccccc", cursor.getString(1) + " " + cursor.getString(2));
12 //                    }
13                     Log.i("dddddddd",cursor.getString(1));
14                 }
15             }
16         });

 

改正后的程序,用循环来输出

 1 btn_search.setOnClickListener(new View.OnClickListener() {
 2             @Override
 3             public void onClick(View v) {
 4                 String key = et_username.getText().toString();
 5                 Cursor cursor = dbOpenHelper.getReadableDatabase().query("tb_user",null,"username=?",new String[]{key}, null,null,null);
 6 
 7                 if (cursor.getCount() == 0) {
 8                     Toast.makeText(MainActivity.this,"很遗憾,没有相关记录",Toast.LENGTH_SHORT).show();
 9                 } else {
10                     while (cursor.moveToNext()) {
11                         Log.i("cccccccccc", cursor.getString(1) + " " + cursor.getString(2));
12                     }
13 //                    Log.i("dddddddd",cursor.getString(1));
14                 }
15             }
16         });

 

android获取数据库查询的结果

标签:roi   崩溃   输出   one   help   length   over   cccccc   query   

原文地址:https://www.cnblogs.com/hemeiwolong/p/12442123.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!