public class DBCreation extends SQLiteOpenHelper
{
Context context;
public DBCreation(Context context)
{
super(context, "LBRDatabase", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) throws SQLException
{
db.execSQL("create table Reminders(id integer primary key autoincrement,description text,address text not null,latitude double not null,longitude double not null,radius text,reminderdate text,remindertime text);");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
try
{
db.execSQL("drop table if exists Reminders ");
onCreate(db);
}
catch (Exception e)
{
Toast.makeText(context, ""+e, Toast.LENGTH_LONG).show();
}
}
}
这段代码有什么问题?它给了我以下错误?
06-18 08:54:30.843: E/Database(6452): Error inserting Reminders
06-18 08:54:30.843: E/Database(6452): android.database.sqlite.SQLiteException: no such table: Reminders: , while compiling: INSERT INTO Reminders(radius, longitude, latitude, reminderdate, address, description, remindertime) VALUES(?, ?, ?, ?, ?, ?, ?);
正在创建表。插入的顺序也不正确。首先是半径,然后是经度,然后是经度,这不是我创建表的顺序。
public class DBOperations
{
Context context;
SQLiteDatabase db;
DBCreation createdb;
public DBOperations(Context context)
{
this.context = context;
createdb = new DBCreation(context);
}
public DBCreation OpenDB() throws SQLException
{
db = createdb.getWritableDatabase();
return createdb;
}
public void CloseDB()
{
db.close();
}
public long addReminder(String description,String address,double latitude,double longitude,String radius,String date,String time)
{
ContentValues cv = new ContentValues();
cv.put("description", description);
cv.put("address", address);
cv.put("latitude", latitude);
cv.put("longitude", longitude);
cv.put("radius", radius);
cv.put("reminderdate", date);
cv.put("remindertime", time);
return db.insert("Reminders", null, cv);
}
public long deleteReminder(int id)
{
return db.delete("Reminders", "_ID="+id, null);
}
public long updateReminder(int id,String desc,String addr,double lat,double lon,int radius,String date,String time)
{
ContentValues cv = new ContentValues();
cv.put("description", desc);
cv.put("address", addr);
cv.put("latitude", lat);
cv.put("longitude", lon);
cv.put("radius", radius);
cv.put("reminderdate", date);
cv.put("remindertime", time);
return db.update("Reminders", cv, "_ID="+id, null);
}
public Cursor showReminders()
{
Cursor c = db.query("Reminders", null, null , null, null, null, null);
if(c!=null)
{
return c;
}
else
{
return null;
}
}
}