【问题标题】:Insertion issue in SQLite AndroidSQLite Android 中的插入问题
【发布时间】:2014-04-02 06:31:43
【问题描述】:

我正在尝试将数据插入数据库,除了product_full_node 之外,所有字段都被插入。但是当我在更新时,一切都在更新。我的情况有点奇怪。

我有一个包含以下列的表格:

Primary Key (Auto Incremented ) , nid , product_name, product_belongs_category, 
product_status, product_rating, product_full_node, 

private static final String CREATE_PRODUCT_DETAILS_TABLE = "CREATE TABLE "
            + PRODUCT_DETAILS_TABLE
            + "("
            + _NID
            + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + PTID
            + " INTEGER ,"
            + NID
            + " INTEGER NOT NULL UNIQUE, "
            + PRODUCT_NAME
            + " TEXT, "
            + PRODUCT_BELONGS_CATEGORY
            + " TEXT, "
            + PRODUCT_STATUS
            + " INTEGER, "
            + PRODUCT_RATING
            + " INTEGER, "
            + PRODUCT_FULL_NODE + " TEXT);";

这是我的插入查询:

public long insertProductDetailsData(String nid, String tid,
        String productName, String productBelongsCategory,
        Integer productRating, String productJsonResponse,
        String publishedStatus) {
    SQLiteDatabase sqliteDB = dbHandler.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    Integer tidInteger = Integer.valueOf(tid);
    Integer nidInteger = Integer.valueOf(nid);
    Integer publishedStatusInteger = Integer.valueOf(publishedStatus);
    contentValues.put(DatabaseHandler.PTID, tidInteger);
    contentValues.put(DatabaseHandler.NID, nidInteger);
    contentValues.put(DatabaseHandler.PRODUCT_NAME, productName);
    contentValues.put(DatabaseHandler.PRODUCT_BELONGS_CATEGORY,
            productBelongsCategory);
    contentValues.put(DatabaseHandler.PRODUCT_STATUS,
            publishedStatusInteger);
    contentValues.put(DatabaseHandler.PRODUCT_RATING, productRating);
    contentValues.put(DatabaseHandler.PRODUCT_FULL_NODE,
            "productJsonResponse");
    long id = 0;
    try {
        id = sqliteDB.insert(DatabaseHandler.PRODUCT_DETAILS_TABLE, null,
                contentValues);
        dbHandler.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return id;
}

这是我的更新:

public int updateProductDetailsData(String nid, String tid,
        String productName, String productBelongsCategory,
        Integer productRating, String productJsonResponse,
        String publishedStatus) {
    SQLiteDatabase sqliteDB = dbHandler.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    Integer tidInteger = Integer.valueOf(tid);
    Integer publishedStatusInteger = Integer.valueOf(publishedStatus);
    contentValues.put(DatabaseHandler.PTID, tidInteger);
    contentValues.put(DatabaseHandler.PRODUCT_NAME, productName);
    contentValues.put(DatabaseHandler.PRODUCT_BELONGS_CATEGORY,
            productBelongsCategory);
    contentValues.put(DatabaseHandler.PRODUCT_RATING, productRating);
    contentValues.put(DatabaseHandler.PRODUCT_FULL_NODE,
            productJsonResponse);
    contentValues.put(DatabaseHandler.PRODUCT_STATUS,
            publishedStatusInteger);
    String[] condition = { nid };
    int id = sqliteDB.update(DatabaseHandler.PRODUCT_DETAILS_TABLE,
            contentValues, DatabaseHandler.NID + " =? ", condition);
    dbHandler.close();
    return id;
}

【问题讨论】:

    标签: android sqlite database-connection android-sqlite


    【解决方案1】:

    改变

    contentValues.put(DatabaseHandler.PRODUCT_FULL_NODE, "productJsonResponse");
    

    contentValues.put(DatabaseHandler.PRODUCT_FULL_NODE, productJsonResponse);
    

    【讨论】:

    • @user3154663 如果对您有帮助,请不要忘记接受答案:)
    • @Manish 永远不会忘记这一点。
    • @user3154663 一个人从错误中学到的最好的教训。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-25
    • 1970-01-01
    • 2020-08-21
    • 1970-01-01
    相关资源
    最近更新 更多