创建SQLite DB时出错

时间:2012-02-12 22:08:04

标签: android database eclipse sqlite insert

我在尝试将数据插入SQL DB时收到错误。该错误表明我的uName列在尝试将数据插入该列时不存在。根据我的观察,应该创建此列。我可能会遗漏一些东西。另一只眼睛可能会有所帮助。

logcat的:

01-23 20:20:15.532:E / Database(2322):插入uName = xxxx时出错wUrl = xxxxxxxx sName = xxxx pWord = xxxx

01-23 20:20:15.532:E / Database(2322):android.database.sqlite.SQLiteException:table infoTable没有名为uName:的列,在编译时:INSERT INTO infoTable(uName,wUrl,sName,pWord )VALUES(?,?,?,?);

数据库创建:

        String sqlDataStore = "create table if not exists " +
        TABLE_NAME_INFOTABLE + " ("+ BaseColumns._ID + " integer primary key autoincrement,"

                    + COLUMN_NAME_SITE + "text not null,"
                    + COLUMN_NAME_ADDRESS + "text not null,"
                    + COLUMN_NAME_USERNAME + "text not null,"
                    + COLUMN_NAME_PASSWORD + "text not null)";

        db.execSQL(sqlDataStore);

这是我的班级:

public class dataStore扩展了SQLiteOpenHelper {

//Table attributes
public static final String DATABASE_NAME = "SiteLogindb";
public static final int DATABASE_VERSION = 1;
public static final String TABLE_NAME_INFOTABLE = "infoTable";

// Data attributes
public static final String COLUMN_NAME_SITE = "sName";
public static final String COLUMN_NAME_ADDRESS = "wUrl";
public static final String COLUMN_NAME_USERNAME = "uName";
public static final String COLUMN_NAME_PASSWORD = "pWord";


public dataStore(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        // TODO Auto-generated constructor stub
    }

5 个答案:

答案 0 :(得分:0)

尝试将DB_Version更改为2:

public static final int DATABASE_VERSION = 2;

答案 1 :(得分:0)

在表定义的末尾添加分号,就像这里解决了你的问题一样

TABLE_NAME_INFOTABLE + " ("+ BaseColumns._ID + " integer primary key autoincrement,"

                        + COLUMN_NAME_SITE + "text not null,"
                        + COLUMN_NAME_ADDRESS + "text not null,"
                        + COLUMN_NAME_USERNAME + "text not null,"
                        + COLUMN_NAME_PASSWORD + "text not null);";

答案 2 :(得分:0)

在文字" text.....

之前的双引号后,您在此处缺少空格
+ COLUMN_NAME_SITE + " text not null,"
+ COLUMN_NAME_ADDRESS + " text not null,"
+ COLUMN_NAME_USERNAME + " text not null,"
+ COLUMN_NAME_PASSWORD + " text not null)";

希望有所帮助

答案 3 :(得分:0)

见下文:

        String sqlDataStore = "create table if not exists " +
        TABLE_NAME_INFOTABLE + " ("+ BaseColumns._ID + " integer primary key autoincrement,"

                    + COLUMN_NAME_SITE + " text not null,"
                    + COLUMN_NAME_ADDRESS + " text not null,"
                    + COLUMN_NAME_USERNAME + " text not null,"
                    + COLUMN_NAME_PASSWORD + " text not null);";

        db.execSQL(sqlDataStore);

答案 4 :(得分:0)

通过从模拟器中删除数据库解决了

问题。

转到DDMS,然后转到文件资源管理器,然后打开数据 - > --->数据 - >然后你的包裹--->然后数据库,在这里你有你的数据库,你可以通过点击右上角的“ - ”符号删除它。