我已經在第一個項目中嘗試數據庫功能。第一個項目沒有錯。之後,即時通訊嘗試與另一個項目,但結果是Sqlite返回:錯誤代碼= 1,msg =沒有這樣的表:登錄 ..即時通訊已經檢查從前一個項目的代碼,一切都是一樣的,但我不知道爲什麼它會發生。sqlite返回:錯誤代碼= 1,msg =沒有這樣的表:登錄
我使用的工具是Eclipse Juno。
MainActivity.java 這是插入數據的函數。
LoginEntity LoginE = new LoginEntity(LoginID, LoginPassword);
LoginDA login = new LoginDA(this);
login.open();
login.createLogin(LoginE);
LoginEntity.java 這個文件是爲登錄類(setter和getter)
public class LoginEntity {
private String LoginID;
private String LoginPassword;
public LoginEntity(){
}
public LoginEntity(String LoginID, String LoginPassword) {
this.LoginID = LoginID;
this.LoginPassword = LoginPassword;
}
public String getLoginID() {
return LoginID;
}
public void setLoginID(String LoginID) {
this.LoginID = LoginID;
}
public String getLoginPassword() {
return LoginPassword ;
}
public void setLoginPassword(String LoginPassword) {
this.LoginPassword = LoginPassword;
}
LoginDA.java 數據庫處理程序
public class LoginDA {
private static final String LoginID = "LoginID";
private static final String LoginPassword = "LoginPassword";
private static final String DATABASE_NAME = "LecturerStudentAppointment";
public static final String DATABASE_TABLE = "Login";
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 + " (" +
LoginID + " INTEGER PRIMARY, " +
LoginPassword + " TEXT NOT NULL);" );
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
onCreate(db);
}
}
public LoginDA(Context c){
ourContext =c;
}
public LoginDA open() throws SQLException{
ourHelper = new DbHelper(ourContext);
ourDatabase = ourHelper.getWritableDatabase();
return this;
}
public void close(){
}
public long createLogin(LoginEntity LoginEntity) {
// TODO Auto-generated method stub
ContentValues cv = new ContentValues();
cv.put(LoginID, LoginEntity.getLoginID());
cv.put(LoginPassword, LoginEntity.getLoginPassword());
return ourDatabase.insert(DATABASE_TABLE, null, cv);
}
你確定你的表名是登錄?還是LoginEntity? – NerosE
yes .. _DATABASE_TABLE =「Login」; _ LoginEntity作爲一個類(構造函數,setter和getter)..或者我在聲明數據庫時出錯了? – Daisy
@NerosE感謝您的意見 – Daisy