android sqlite插入到哪里 [英] android sqlite insert into where

查看:24
本文介绍了android sqlite插入到哪里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想插入现有应用数据表的应用类别.我不知道我这样做是否正确,但在我正在做的事情中,我也遇到了这个错误.

i want to insert category of the application of the existing table of application data. I do not know if im doing it correct, but in what i am doing i get this error as well.

我该怎么做才能正确?

主要活动

    AlertDialog.Builder builder = new AlertDialog.Builder(
            MainActivity.this);
    builder.setTitle("Please Select Category of : " + AppName); 
    builder.setItems(shareItems,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int item) {
                    // TODO Auto-generated method stub
                    String itemz = String.valueOf(shareItems[item]);
                    mySQLiteAdapter.insertcategory(AppName, itemz);
                }
            });
    AlertDialog shareAlert = builder.create();
    shareAlert.show();

处理程序

 public long insertcategory(String AppName, String itemz) {
            // TODO Auto-generated method stub
            Cursor crack = sqlitedb.rawQuery("INSERT INTO " + KEY_CATEGORY
                    + " VALUES ( ' " + itemz + " ' ) WHERE " + KEY_NAME
                    + " LIKE ?", new String[] { "%" + AppName+ "%" });
            return 0;
        }

更新的查询这是我用来更新表的.itemz 的值是游戏",但没有更新

updated query This is what i used to update the table. itemz gets the value as 'Game' but it does not getting updated

public long insertcategory(String AppName, String itemz) {
        // TODO Auto-generated method stub

        ContentValues values = new ContentValues();
        values.put(KEY_CATEGORY, itemz);
        return sqlitedb.update(MYDATABASE_TABLE, values, KEY_NAME + " LIKE ?",
                new String[] { "%" + AppName + "%" });

    }

表创建为

private static final String SCRIPT_CREATE_DATABASE = "create table "
            + MYDATABASE_TABLE + " (" + KEY_ID
            + " integer primary key autoincrement, " + KEY_NAME
            + " text not null, " + KEY_PACK + " text not null, " + KEY_PERM
            + " text not null, " + KEY_LEVEL + " text not null, "
            + KEY_CATEGORY + " text);";

推荐答案

INSERT 命令没有 WHERE 子句,因为它插入了一个全新的记录.

The INSERT command does not have a WHERE clause because it inserts a completely new record.

您似乎想设置/更改现有记录中的值.这将通过 UPDATE 命令完成:

It appears you want to set/change the value in an existing record. This would be done with an UPDATE command:

UPDATE MyTable SET category = 'Entertainment' WHERE name LIKE ?

这篇关于android sqlite插入到哪里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆