android.database.sqlite.SQLiteException:表中有没有这样的列 [英] android.database.sqlite.SQLiteException: table has no such column

查看:390
本文介绍了android.database.sqlite.SQLiteException:表中有没有这样的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想这是一个很常见的问题,搜索我发现我不是谁遇到了这样的问题只有一个网页是的,我知道有几乎相同标题的问题,但是没有帮助解决我所面临的问题......让我们从头开始。

So I guess it is a very common issue, searching the web I found that I am not the only one who faced a such issue and yes I know that there is a question with almost the same title, however that did not help to solve the issue I am facing ... so let's start from the beginning

我只是想插入我创建一个表。
此表有三列:ID,姓名,价值,并作为下创建

I am simply trying to insert into a table that I created. This table has three columns: "id", "name", "value", and was created as following

public static final String TABLE_NAME = "cookie";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_NAME = "name";
public static final String COLUMN_VALUE = "val";

private static final String DATABASE_NAME = "commments.db";
private static final int DATABASE_VERSION = 2;

// Database creation sql statement
private static final String DATABASE_CREATE = "create table "
  + TABLE_NAME + "(" 
  + COLUMN_ID + " integer primary key autoincrement, " 
  + COLUMN_VALUE + "text not null, "
  + COLUMN_NAME + " text not null"
  + ");";

public MySQLiteHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase database) {
  database.execSQL(DATABASE_CREATE);
}

现在我试图插入此表如下

Now I am trying to insert into this table as following

ContentValues values = new ContentValues();
        values.put(MySQLiteHelper.COLUMN_NAME, "username");
        values.put(MySQLiteHelper.COLUMN_VALUE, username);

        long insertId = database.insert(MySQLiteHelper.TABLE_NAME, null, values);
        Cursor cursor = database.query(MySQLiteHelper.TABLE_NAME, allColumns, MySQLiteHelper.COLUMN_ID + " = " + insertId, null, null, null, null);
        cursor.moveToFirst();
        nameValuePair newComment = cursorToNameValuePair(cursor);
        cursor.close();

但是我得到这个错误

However I am getting this error

table cookie has no column named val 

我搜索了类似的问题在网上,大多数在这里谈论的是一个变化的解决方案发生了数据库,所以我需要为

I searched for similar issues online, most of the solution where talking about a change happened to the database so I need to either

1未安装该应用程序
2 - 更新1数据库版本号为3

1- Un-install the application before trying to run in debugging mode again 2- update the database version from 1 to 3

不过这并没有帮助。所以期待着您的解决方案:)

However that did not help .. So looking forward for your solutions :)

推荐答案

问题是在这里

+ COLUMN_VALUE + "text not null, "

DATABASE_CREATE 字符串。你错过了间距的列名的和的字段类型

into DATABASE_CREATE String. You missed space between column name and column type.

这应该是

+ COLUMN_VALUE + " text not null, "

这篇关于android.database.sqlite.SQLiteException:表中有没有这样的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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