在android连接到SQLite数据库时不执行create table query

时间:2017-10-27 04:59:04

标签: android android-sqlite

private static final String dbname="student.db";
private static final String tblname="detail";
private static final String c1="uname";
private static final String c2="id";
private static final String c3="pass";
private static final String c4="add";
private static final String c5="gender";
private static final String c6="sequrity";
private static final String c7="answer";


public Databasehelper(Context context) 
{
    super(context, dbname, null, 1);

}

@Override
public void onCreate(SQLiteDatabase db) 
{
    String q= "create table "+tblname+"("
        +c1+" varchar(10),"
        +c2+" varchar(20),"
        +c3+" varchar(10),"
        +c4+" varchar(100),"
        +c5+" varchar(10),"
        +c6+" varchar(100),"
        +c7+" varchar(10))";

        db.execSQL(q);
}

在create table中的上述编码中定义Error

2 个答案:

答案 0 :(得分:0)

您可以使用此

更新查询
"create table "+tblname+"("+c1+" TEXT, "+c2+" TEXT, "+c3+" TEXT, "+c4+" TEXT, "+c5+" TEXT, "+c6+" TEXT, "+c7+" TEXT)";

在SQLite中,TEXT与VARCHAR相同,您可以使用TEXT as this answer

您还可以查看常见问题的sqlite here

答案 1 :(得分:0)

for i in f1(txt): print(i) sqlite keyword。因此,它不能用作标识符,例如列名。

将该列重命名为非关键字。