I’m creating an Database for my Application that I am creating however whenever I run my application and try to enter some information into my database nothing happens and an error message is displayed in the LogCat.
The full error message is:
“04-09 17:22:18.208: E/Database(484): Failure 1 (near “NULLenergy_rates”: syntax error) on 0x2d7a30 when preparing ‘CREATE TABLE ApplianceDetails (_id INTEGER PRIMARY KEY, appliance_name TEXT NOT NULL, appliance_wattage TEXT NOT NULLenergy_rates TEXT NOT NULL);’.
It is associated with this code:
public class Database {
public static final String KEY_ROWID = "_id";
public static final String KEY_NAME = "appliance_name";
public static final String KEY_WATTAGE = "appliance_wattage";
public static final String KEY_ENERGY = "energy_rates";
private static final String DATABASE_NAME = "TheApplianceKeeperdb";
private static final String DATABASE_TABLE = "ApplianceDetails";
private static final int DATABASE_VERSION = 1;
private DbHelper ourHelper;
private final Context ourContext;
private SQLiteDatabase ourDatabase;
private static class DbHelper extends SQLiteOpenHelper{
public DbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
KEY_NAME + " TEXT NOT NULL, " +
KEY_WATTAGE + " TEXT NOT NULL" +
KEY_ENERGY + " TEXT NOT NULL);"
);
}
any help on how I can fix this error would be greatly appreciated
Add a comma and space changing
KEY_WATTAGE + " TEXT NOT NULL" +toKEY_WATTAGE + " TEXT NOT NULL, " +