我在我的本地數據庫(sqlite)中插入了一些日期。但是當我想選擇這些數據時,遊標不是構建xml並跳過此塊。我在我的sqlite中有一行。有什麼想法?光標不在SQLite中工作
這是我的代碼:`
public void insertMessages(int msgid,String msgdesc, String date, int createdby,int to) {
SQLiteDatabase myDatabase = this.getWritableDatabase();
String query = "INSERT INTO Messages (_id,msgdesc,date,createdby,sendto) "+
" VALUES ("+msgid+",'"+msgdesc+"','"+date+"',"+createdby+","+to+")";
SQLiteStatement st = myDatabase.compileStatement(query);
try {
st.execute();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
myDatabase.close();
Log.i("insert","insert Messages completed");
}
public String getMessages(int to) {
SQLiteDatabase myDatabase = this.getWritableDatabase();
String xml = null;
try {
String query = "SELECT _id,msgdesc,date,createdby,sendto from Messages Where sendto="+to+"";
Cursor cs = myDatabase.rawQuery(query, null);
xml = "<messagelist>";
*****if (cs.moveToFirst()) {*****
do {
xml += "<messages>";
xml += "<msgid>"+cs.getInt(cs.getColumnIndex("_id"))+"</msgid>";
xml += "<msgdesc>"+cs.getString(cs.getColumnIndex("msgdesc"))+"</msgdesc>";
xml += "<date>"+cs.getString(cs.getColumnIndex("date"))+"</date>";
xml += "<createdby>"+cs.getInt(cs.getColumnIndex("createdby"))+"</createdby>";
xml += "<to>"+cs.getInt(cs.getColumnIndex("sendto"))+"</to>";
xml += "</messages>";
} while (cs.moveToNext());
}
xml += "</messagelist>";
cs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
myDatabase.close();
Log.i("select","select completed");
return xml;
}`
什麼是錯誤消息? – smk
你是否收到任何錯誤信息? – GrIsHu
嘗試改變sendto =「+ to +」「>> sendto ='」+加+''「加''比較字符串 – AAnkit