android.database.sqlite.SQLiteException: duplicate column name: text (code 1): 之类的问题解决

最近在回看郭霖的第一行代码,在看到数据库sqllite部分时,自己新建了两个表,建表的语句如下:

(1)

public static    final String CREATE_DB_BOOK = "create table book("
           + "id integer primary key autoincrement,"
           + "author text,"
           + "price real,"
           + "pages integer,"
           + "name text)";
 public static   final String CREATE_DB_PERSON = "create table person("
           + "id integer primary key autoincrement,"
           + "name, text,"
           + "sex ,text)";

(2)

public static    final String CREATE_DB_BOOK = "create table book("
           + "id integer primary key autoincrement,"
           + "author text,"
           + "price real,"
           + "pages integer,"
           + "name text)";
 public static   final String CREATE_DB_PERSON = "create table person("
           + "id integer primary key autoincrement,"
           + "name text,"
           + "sex text)";

错误截图:

android.database.sqlite.SQLiteException: duplicate column name: text (code 1): 之类的问题解决_第1张图片


对就是这两个表,建成以后,死活报如上错误,虚拟机不行,换真机,各种尝试均失败,后来经过一番摸索,才发现自己的建表语句有bug  。。。。。。

   仔细看,person 表,自己手残不小心在sql语句中name和sex后加了一个逗号,关键就在这,加上这个逗号就表示,这个表中有了重复字段,这数据库是不能忍的。

   记录在这给自己提个醒,以后写代码,一定要认真。


你可能感兴趣的:(Android学习总结)