添付のコードを見て、私がデータベースに値を挿入または選択しない理由を誰にでも教えてください。私は何もしていないので、私は何をしていないのかを知ることさえできません。私が知っているのは、選択クエリを実行するとカーソルには何も含まれていないということです。上記のコード変更後のAndroidのSQLiteデータベースの挿入/選択が動作しない
SQLiteDatabase db = new DatabseHelper(this).getWritableDatabase();
// db.execSQL(mDATABASE_CREATE);
String id = "1";
String feedback = "this is some feedback";
String expiredAt = "12:00";
String priority = "1";
String read = "false";
String sql = "INSERT INTO feedbackTable (_id, feedback, expiredAt, priority, read) VALUES (\""+id+"\", \""+feedback+"\", \""+expiredAt+"\", \""+priority+"\", \""+read+"\")";
db.rawQuery(sql, null);
Cursor result = db.rawQuery("SELECT * FROM feedbackTable", null);
result.moveToFirst();
String rfeedback="";
while(!result.isAfterLast()){
rfeedback=result.getString(1);
}
Log.e("returned feedback", "inserted feedback "+rfeedback);
db.close();
第二の問題
ありがとう:
SQLiteDatabase db = new DatabseHelper(this).getWritableDatabase();
String id = "1";
String feedback = "this is some feedback";
String expiredAt = "12:00";
String priority = "1";
String read = "false";
String sql = "INSERT INTO feedbackTable (_id, feedback, expiredAt, priority, read) VALUES (\""+id+"\", \""+feedback+"\", \""+expiredAt+"\", \""+priority+"\", \""+read+"\");";
ContentValues values = new ContentValues(5);
values.put("_id", "1");
values.put("feedback", "some feedback");
values.put("expiredAt", "12:00");
values.put("priority", "1");
values.put("read", "false");
db.insert("feedbackTable", "_id", values);
Cursor result = db.rawQuery("SELECT * FROM feedbackTable", null);
//db.execSQL(sql);
//insert(feedbackTable, nullColumnHack, values)
//.rawQuery(sql, null);
result.moveToFirst();
String rfeedback="";
while(!result.isAfterLast()){
rfeedback=result.getString(1);
}
Log.e("returned feedback", "inserted feedback "+rfeedback);
db.close();
ExecSqlの両方を使用して
だけ応答を待ってハング自分のアプリケーションをdb.insert。上記のLog.eには決して行きません。このアクションは画面が描画される前にoncreateメソッドで行われるため、空の画面しか表示されません。どんな考え?
[1]の記事を参照してください。 db.rawQuery()の代わりにdb.insert()を使用しようとしています。 [1]:http://stackoverflow.com/questions/2616130/android-insert-into-sqlite-database – Jack
はい、私は見る - 私はExecSqlのかdb.insertを使用しているsould。私は両方を試してみましたが、現在は両方に新しい問題があるので、もう1つ問題があるはずです。 –
余分な引用符を取り除きます。文字列に "value"を挿入する必要はありません。まったく囲みませんか、一重引用符を使用してください " – Jack