我创建了下表
public class LoginDBAdapter {
static final String DATABASE_NAME = "login.db";
static final int DATABASE_VERSION = 2;
public static final String COL_ROWID= "rowid";
public static final String COL_USERNAME= "username";
public static final String COL_EMAIL= "email";
public static final String COL_PASSWORD= "password";
// TODO: Create public field for each column in your table.
// SQL Statement to create a new database.
static final String DATABASE_CREATE = "create table "+"LOGIN"+
"( " +"rowid"+" integer primary key autoincrement,"+ " username text,"+" password text,"+" email text); ";
// Variable to hold the database instance
public SQLiteDatabase db;
// Context of the application using the database.
private final Context context;
// Database open/upgrade helper
private DBHelper dbHelper;
public LoginDBAdapter(Context _context) {
context = _context;
dbHelper = new DBHelper(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public LoginDBAdapter open() throws SQLException {
db = dbHelper.getWritableDatabase();
return this;
}
public void close() {
db.close();
}
public SQLiteDatabase getDatabaseInstance(){
return db;
}
public void insertEntry(String userName,String password,String email){
ContentValues newValues = new ContentValues();
// Assign values for each row.
newValues.put("USERNAME", userName);
newValues.put("PASSWORD",password);
newValues.put("EMAIL", email);
db.insert("LOGIN", null, newValues);
///Toast.makeText(context, "Reminder Is Successfully Saved", Toast.LENGTH_LONG).show();
}
public int deleteEntry(String Email){
//String id=String.valueOf(ID);
String where="USERNAME=?";
int numberOFEntriesDeleted= db.delete("LOGIN", where, new String[]{Email}) ;
// Toast.makeText(context, "Number fo Entry Deleted Successfully : "+numberOFEntriesDeleted, Toast.LENGTH_LONG).show();
return numberOFEntriesDeleted;
}
public String getSinlgeEntry(String Email){
Cursor cursor=db.query("LOGIN", null, " USERNAME=?", new String[]{Email}, null, null, null);
if(cursor.getCount()<1) {
// UserName Not Exist
cursor.close();
return "NOT EXIST";
}
cursor.moveToFirst();
String password= cursor.getString(cursor.getColumnIndex("PASSWORD"));
cursor.close();
return password;
}
public void updateEntry(String userName,String password,String email){
// Define the updated row content.
ContentValues updatedValues = new ContentValues();
// Assign values for each row.
updatedValues.put("USERNAME", userName);
updatedValues.put("PASSWORD",password);
updatedValues.put("EMAIL", email);
String where="USERNAME = ?";
db.update("LOGIN",updatedValues, where, new String[]{userName});
}
}
我收到以下错误
06-11 13:48:00.512: E/SQLiteLog(938): (1) table LOGIN has no column named EMAIL
06-11 13:48:00.607: E/SQLiteDatabase(938): Error inserting EMAIL=aaa USERNAME=swe PASSWORD=111
06-11 13:48:00.607: E/SQLiteDatabase(938): android.database.sqlite.SQLiteException: table LOGIN has no column named EMAIL (code 1): , while compiling: INSERT INTO LOGIN(EMAIL,USERNAME,PASSWORD) VALUES (?,?,?)
06-11 13:48:00.607: E/SQLiteDatabase(938): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
06-11 13:48:00.607: E/SQLiteDatabase(938): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
06-11 13:48:00.607: E/SQLiteDatabase(938): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
06-11 13:48:00.607: E/SQLiteDatabase(938): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
06-11 13:48:00.607: E/SQLiteDatabase(938): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
06-11 13:48:00.607: E/SQLiteDatabase(938): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
06-11 13:48:00.607: E/SQLiteDatabase(938): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
06-11 13:48:00.607: E/SQLiteDatabase(938): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
06-11 13:48:00.607: E/SQLiteDatabase(938): at com.androidhive.loginandregister.LoginDBAdapter.insertEntry(LoginDBAdapter.java:55)
06-11 13:48:00.607: E/SQLiteDatabase(938): at com.androidhive.loginandregister.RegisterActivity$2.onClick(RegisterActivity.java:59)
06-11 13:48:00.607: E/SQLiteDatabase(938): at android.view.View.performClick(View.java:4204)
06-11 13:48:00.607: E/SQLiteDatabase(938): at android.view.View$PerformClick.run(View.java:17355)
06-11 13:48:00.607: E/SQLiteDatabase(938): at android.os.Handler.handleCallback(Handler.java:725)
06-11 13:48:00.607: E/SQLiteDatabase(938): at android.os.Handler.dispatchMessage(Handler.java:92)
06-11 13:48:00.607: E/SQLiteDatabase(938): at android.os.Looper.loop(Looper.java:137)
06-11 13:48:00.607: E/SQLiteDatabase(938): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-11 13:48:00.607: E/SQLiteDatabase(938): at java.lang.reflect.Method.invokeNative(Native Method)
06-11 13:48:00.607: E/SQLiteDatabase(938): at java.lang.reflect.Method.invoke(Method.java:511)
06-11 13:48:00.607: E/SQLiteDatabase(938): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-11 13:48:00.607: E/SQLiteDatabase(938): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-11 13:48:00.607: E/SQLiteDatabase(938): at dalvik.system.NativeStart.main(Native Method)
06-11 13:48:12.947: I/Choreographer(938): Skipped 79 frames! The application may be doing too much work on its main thread.
06-11 13:48:13.287: D/dalvikvm(938): GC_CONCURRENT freed 155K, 9% free 3064K/3364K, paused 95ms+183ms, total 746ms
06-11 13:48:15.527: I/Choreographer(938): Skipped 238 frames! The application may be doing too much work on its main thread.
06-11 13:48:16.347: I/Choreographer(938): Skipped 43 frames! The application may be doing too much work on its main thread.
06-11 13:48:17.917: I/Choreographer(938): Skipped 89 frames! The application may be doing too much work on its main thread.
06-11 13:48:21.047: I/Choreographer(938): Skipped 40 frames! The application may be doing too much work on its main thread.
06-11 13:49:47.471: I/Choreographer(938): Skipped 33 frames! The application may be doing too much work on its main thread.
06-11 13:50:06.797: I/Choreographer(938): Skipped 40 frames! The application may be doing too much work on its main thread.
感谢帮助