sqlite資料庫中第一條資料查不出來!

來源:互聯網
上載者:User

標籤:

/**
*  * Title: selectAllPhone  *Description:查詢所有的Phone對象  * @return  * @see
* com.sms.ntlm.dao.PhoneDao#selectAllPhone()     
*/
@SuppressLint("SimpleDateFormat")
@SuppressWarnings("deprecation")
@Override
public List<Phone> selectAllPhone() {
Cursor cursor=null;
List<Phone> list=new ArrayList<Phone>();
String sql="select * from "+PhoneSQLConstant.TABLE_NAME+";";
db=mOpenHelper.getWritableDatabase();
if(mOpenHelper!=null && db.isOpen()){
// cursor=db.query(PhoneSQLConstant.TABLE_NAME, null, null, null, null, null, null);
cursor=db.rawQuery(sql, null);
}
if (cursor != null) {//原因就是這個地方出錯了:我在這個地方加了個if (cursor != null && cursor.moveToFirst()) {
while (cursor.moveToNext()) {
Phone phone=new Phone();

phone.setPhoneId(cursor.getInt(cursor.getColumnIndex(PhoneSQLConstant.PHONE_ID)));
phone.setPhoneNum(cursor.getString(cursor.getColumnIndex(PhoneSQLConstant.PHONE_NUM)));
phone.setPhoneDate(cursor.getString(cursor.getColumnIndex(PhoneSQLConstant.PHONE_DATE)));

list.add(phone);
}
}
this.closeCursorDB(cursor);
return list;

}


控制台輸出的結果是:05-15 03:12:44.017: I/System.out(12634): testselectAllPhone.size()..............0

我在資料庫中查詢的結果是:

D:\zzz>sqlite3 PhoneMassage.db
SQLite version 3.7.11 2012-03-20 11:35:50
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .table
MyPhone           Phone             android_metadata
sqlite> select * from MyPhone
   ...> ;
1|1234|2015-05-15
sqlite> ^C


sqlite資料庫中第一條資料查不出來!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.