我想创建一个表,但它给了我一个错误。

时间:2022-10-07 08:01:57

This code is to create a new table.

此代码用于创建一个新表。

 import android.database.sqlite.SQLiteOpenHelper;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;


public class MySQLHelper extends SQLiteOpenHelper {

    public static final String DATABASE_NAME = "verlaufAufgaben.db";
    public static final int DATABASE_VERSION = 1;

create the table

创建表

    private static final String TABLE_CREATE_VERLAUF = ""
            +"create table VERLAUF ("
            +" ID integer primary key, "
            +" Zahl1 int,) ";


    public MySQLHelper(Context context) 
    {   
        super (context, DATABASE_NAME, null, DATABASE_VERSION);
    }

create SQLiteDatabase

创建SQLiteDatabase

    @Override
    public void onCreate(SQLiteDatabase database)
    {
        database.execSQL(TABLE_CREATE_VERLAUF);
    }

upgrade the database

升级数据库

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
    {
        Log.w(MySQLHelper.class.getName(),
                "Upgrading database from version " + oldVersion + "to "
                + newVersion + ", which all destroy all old data");
        db.execSQL("DROP TABLE IF EXISTS SCANITEM");
        onCreate(db);
    }

}

What's wrong in this code, it shows me an error because of the table?

这段代码有什么问题,因为表格显示了一个错误?

1 个解决方案

#1


3  

you had the table create DDL ending with a comma...remove that!

表create DDL以逗号结尾……删除!

private static final String TABLE_CREATE_VERLAUF = ""
        +"create table VERLAUF ("
        +" ID integer primary key, "
        +" Zahl1 int) ";

#1


3  

you had the table create DDL ending with a comma...remove that!

表create DDL以逗号结尾……删除!

private static final String TABLE_CREATE_VERLAUF = ""
        +"create table VERLAUF ("
        +" ID integer primary key, "
        +" Zahl1 int) ";