当前位置: 移动技术网 > IT编程>移动开发>Android > android.database.sqlite.SQLiteException: duplicate column name: text (code 1): 之类的问题解决

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

2018年09月12日  | 移动技术网IT编程  | 我要评论

北邮ipv6,生死狙击第一季,138度卫星

最近在回看郭霖的第一行代码,在看到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)";

错误截图:

\

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

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

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网