尝试创建数据库时出现此错误:错误消息在此处输入代码 02-23 02:08:46.780: E/Database(32721): Error inserting email=af contact=38 dob=1/8/68 name=ex 02-23 02:08:46.780: E/Database(32721): android.database.sqlite.SQLiteException: 没有这样的表: 配置文件: , 编译时: 插入配置文件 (电子邮件、联系人、出生日期、姓名) 值 (?, ?, ?, ?); 02-23 02:08:46.780: E/Database(32721): atandroid.database.sqlite.SQLiteCompiledSql.native_compile(Native Method) 02-23 02:08:46.780: E/Database(32721): at
package a.vaccination;
import android.content.ContentValues;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class datahandler {
public static final String KEY_ROWID = "id";
public static final String KEY_name = "name";
public static final String KEY_dob = "dob";
public static final String KEY_contact = "contact";
public static final String KEY_email = "email";
private static final String TAG = "DBAdapter";
private static final String DATABASE_NAME = "profile";
private static final String DATABASE_TABLE = "profiles";
private static final int DATABASE_VERSION = 2;
private static final String DATABASE_CREATE
= "create table (id integer primary keyautoincrement, "
+ "name VARCHAR not null, dob date, contact VARCHAR, email VARCHAR);";
private final Context context;
private DatabaseHelper DBHelper;
private SQLiteDatabase db;
public datahandler(Context ctx) {
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}
protected static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
try {
db.execSQL(DATABASE_CREATE);
//db = DBHelper.getWritableDatabase();
} catch (SQLException e) {
e.printStackTrace();
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS contacts");
onCreate(db);
}
}
// ---opens the database---
public datahandler open() throws SQLException {
db = DBHelper.getWritableDatabase();
return this;
}
// ---closes the database---
public void close() {
DBHelper.close();
}
// ---insert a record into the database---
public long insertRecord(String name, String dob, String contact,
String email) {
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_name, name);
initialValues.put(KEY_dob, dob);
initialValues.put(KEY_contact, contact);
initialValues.put(KEY_email, email);
return db.insert(DATABASE_TABLE, null, initialValues);
}
// ---updates a record---
public boolean updateRecord(long rowId, String name, String dob,
String contact, String email) {
ContentValues args = new ContentValues();
args.put(KEY_name, name);
args.put(KEY_dob, dob);
args.put(KEY_contact, contact);
args.put(KEY_email, email);
return db.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0;
}
}