android android - 27 days ago 9
Android Question

I want to create a table but it gives me an error

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

@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?

Answer

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

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