我在嘗試創建數據庫時,此錯誤: 錯誤信息 輸入代碼在這裏 2月2日至23日:08:46.780:E /數據庫(32721):錯誤 插入電子郵件= af contact = 38 dob = 1/8/68 name = ex 02-23 02:08:46.780:E/Database(32721): android.database.sqlite.SQLiteException:no such table: profiles:,while編譯:INSERT INTO配置文件 (email,contact,dob,name)VALUES(?,?,?,?); 02:02:08:46.780:E/Database(32721): atandroid.database.sqlite.SQLiteCompiledSql.native_compile(Native Method) 02-23 02:08:46.780:E/Database(32721):atSQLite數據庫錯誤:找不到表格的Android
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;
}
}
發佈您的代碼。 – 323go 2013-02-22 20:44:50
也附加我的數據庫文件: – Saurabh 2013-02-22 20:45:29
@Saurabh,請盡你最大的努力發佈乾淨的問題,具有良好的格式和最好的英語知識。我現在解決了你的問題。另外,正如323go所說,發佈一些代碼。 – 2013-02-22 21:59:44