Android SQLite插入数据

Android SQLite插入数据,android,sqlite,Android,Sqlite,我正试图用这段代码在我的Android SQLite新创建的数据库中插入一些数据,但它不起作用 以下是错误: 10-19 19:05:39.793: INFO/Database(413): sqlite returned: error code = 1, msg = near ",": syntax error 我知道代码需要一个干净的,但我以后会这样做^^ 代码如下: SQLiteDatabase db = this.sqlHelper.getWritableDatabase(); Cont

我正试图用这段代码在我的Android SQLite新创建的数据库中插入一些数据,但它不起作用

以下是错误:

10-19 19:05:39.793: INFO/Database(413): sqlite returned: error code = 1, msg = near ",": syntax error
我知道代码需要一个干净的,但我以后会这样做^^

代码如下:

SQLiteDatabase db = this.sqlHelper.getWritableDatabase();
ContentValues dv = new ContentValues();
dv.put("`createdTime`", h.createdTime);
dv.put("`type`", h.type);
dv.put("`what`", h.what);
dv.put("`where`", h.where);
dv.put("`readableWhat`", h.readableWhat);
dv.put("`readableWhere`", h.readableWhere);
dv.put("`accuracy`", h.accuracy);
dv.put("`isMnemo`", h.isMnemo);
dv.put("`isPlaceCode`", h.isPlaceCode);
dv.put("`isCoords`", h.isCoords);
dv.put("`isNear`", h.isNear);
dv.put("`isEverywhere`", h.isEverywhere);

Cursor c = db.query("HISTORY",
        new String[]{
                "`type`",
                "`what`",
                "`where`",
                "`readableWhat`",
                "`readableWhere`",
                "`accuracy`",
                "`isMnemo`",
                "`isPlaceCode`",
                "`isCoords`",
                "`isNear`",
                "`isEverywhere`",
        },
        "`type`='" + h.type + "'" + "," +
        "`what`='" + h.what + "'" + "," +
        "`where`='" + h.where + "'" + "," +
        "`readableWhat`='" + h.readableWhat + "'" + "," +
        "`readableWhere`='" + h.readableWhere + "'" + "," +
        "`accuracy`='" + h.accuracy  +"'" + "," +
        "`isMnemo`='" + h.isMnemo + "'" + "," +
        "`isPlaceCode`='" + h.isPlaceCode + "'" + "," +
        "`isCoords`='" + h.isCoords + "'" + "," +
        "`isNear`='" + h.isNear + "'" + "," +
        "`isEverywhere`='" + h.isEverywhere + "'"
        ,
        null, null, null, null);
if (!c.moveToFirst())
{
    PJUtils.log("INSERT " + h.readableWhat + " - " + h.readableWhere);
    db.insertOrThrow("HISTORY", "", dv);
}
else
{
    PJUtils.log("UPDATE " + h.readableWhat + " - " + h.readableWhere);
    db.update("CONFIG",
        dv,
        "`type`='" + h.type + "'" + "," +
        "`what`='" + h.what + "'" + "," +
        "`where`='" + h.where + "'" + "," +
        "`readableWhat`='" + h.readableWhat + "'" + "," +
        "`readableWhere`='" + h.readableWhere + "'" + "," +
        "`accuracy`='" + h.accuracy  +"'" + "," +
        "`isMnemo`='" + h.isMnemo + "'" + "," +
        "`isPlaceCode`='" + h.isPlaceCode + "'" + "," +
        "`isCoords`='" + h.isCoords + "'" + "," +
        "`isNear`='" + h.isNear + "'" + "," +
        "`isEverywhere`='" + h.isEverywhere + "'"
        ,
        null);
}
c.close();
而不是

+ "," +
使用


请尝试以下查询:

            String[] columns = new String[]{
                "type",
                "what",
                "where",
                "readableWhat",
                "readableWhere",
                "accuracy",
                "isMnemo",
                "isPlaceCode",
                "isCoords",
                "isNear",
                "isEverywhere" };
        String selection = "type=? AND what=? AND where=? AND readableWhat=? AND readableWhere=? AND accuracy=? AND isMnemo=? AND isPlaceCode=? AND isCoords=? AND isNear=? AND isEverywhere=?";
        String[] selectionArgs = new String[]{
                h.type,
                h.what,
                h.where,
                h.readableWhat,
                h.readableWhere,
                h.accuracy,
                h.isMnemo,
                h.isPlaceCode,
                h.isCoords,
                h.isNear,
                h.isEverywhere
        };
        Cursor c = db.query("HISTORY", columns, selection, selectionArgs, null, null, null);

你为什么在你的弦上加撇号;我的意思是“'type'=”而不是“type=”?如何以其他方式实现?我指的是你用
类型=?
的方式。你说的是
selectionArgs
参数吗?
            String[] columns = new String[]{
                "type",
                "what",
                "where",
                "readableWhat",
                "readableWhere",
                "accuracy",
                "isMnemo",
                "isPlaceCode",
                "isCoords",
                "isNear",
                "isEverywhere" };
        String selection = "type=? AND what=? AND where=? AND readableWhat=? AND readableWhere=? AND accuracy=? AND isMnemo=? AND isPlaceCode=? AND isCoords=? AND isNear=? AND isEverywhere=?";
        String[] selectionArgs = new String[]{
                h.type,
                h.what,
                h.where,
                h.readableWhat,
                h.readableWhere,
                h.accuracy,
                h.isMnemo,
                h.isPlaceCode,
                h.isCoords,
                h.isNear,
                h.isEverywhere
        };
        Cursor c = db.query("HISTORY", columns, selection, selectionArgs, null, null, null);