欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

程序员文章站 2022-05-01 18:15:49
最近在回看郭霖的第一行代码,在看到sqllite部分时,自己新建了两个表,建表的语句如下: (1) public static final string create_db_book =...

最近在回看郭霖的第一行代码,在看到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): 之类的问题解决

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

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

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