2015-06-06 34 views
0
public class DBhandle { 
    private static final String DATABASE_NAME = "restaurantdatabase"; 
    private static final int DATABASE_VERSION = 1; 
    final Context context; 
    private SQLiteDatabase ourDatabase; 

    //table name 
    private static final String LOGIN_TABLE_NAME = "Login"; 

    //login table column name 
    public static final String KEY_ROWID = "ID"; 
    public static final String A_NAME = "admin_name"; 
    public static final String A_PHONE = "admin_phone"; 

    DatabaseHelper dbHelper; 

    public static class DatabaseHelper extends SQLiteOpenHelper { 

     public DatabaseHelper(Context context) { 
      super(context, DATABASE_NAME, null, DATABASE_VERSION); 
     } 

     @Override 
     public void onCreate(SQLiteDatabase db) { 
      db.execSQL("CREATE TABLE " + LOGIN_TABLE_NAME + " (" + KEY_ROWID 
          + " INTEGER PRIMARY KEY AUTOINCREMENT, " + A_NAME 
          + " TEXT NOT NULL, " + A_PHONE + " TEXT NOT NULL);" 
      ); 
     } 

     public long insertEntry(String userName, String password) { 
      //SQLiteDatabase db = this.getWritableDatabase(); 
      ContentValues newValues = new ContentValues(); 
      // Assign values for each row. 
      newValues.put("A_NAME", userName); 
      newValues.put("A_PHONE", password); 

      // Insert the row into your table 
      return ourDatabase.insert(LOGIN_TABLE_NAME, null, newValues); 
      //Toast.makeText(context, "Reminder Is Successfully Saved", Toast.LENGTH_LONG).show(); 
     } 
    } 
} 

我試圖將數據插入我收到一個數據庫(?,?)但以下情況除外:表(登錄)沒有名爲(A_NAME)(代碼1)列:,在編譯:INSERT INTO登錄(A_NAME,A_PHONE)VALUES

android.database.sqlite.SQLiteException: table Login has no column named A_NAME (code 1): , while compiling: INSERT INTO Login(A_NAME,A_PHONE) VALUES (?,?). 
+0

只需移除(「)鑰匙周圍的雙人牀。 –

回答

0

當這些實際上是最終的靜態字符串常量時,您將字段「A_NAME」和「A_PHONE」稱爲字符串,因此實際列名稱爲「admin_name」和「admin_phone」。

您需要更改這些兩行:

// Assign values for each row. 
newValues.put("A_NAME", userName); 
newValues.put("A_PHONE", password); 

你有兩個選擇:

要麼你指的是實際的列名:

newValues.put("admin_name", userName); 
newValues.put("admin_phone", password); 

或使用靜態的最後常數沒有雙引號

newValues.put(A_NAME, userName); 
newValues.put(A_PHONE, password); 
+0

你是maseeha – sajjan

+0

誰投下了答案,請在評論中註明一個理由 – omerio

0
public long insertEntry(String userName,String password) 
{ 
    //SQLiteDatabase db = this.getWritableDatabase(); 
    ContentValues newValues = new ContentValues(); 
    // Assign values for each row. 
    newValues.put(A_NAME, userName); 
    newValues.put(A_PHONE, password); 


    // Insert the row into your table 
    return ourDatabase.insert(LOGIN_TABLE_NAME, null, newValues); 
    //Toast.makeText(context, "Reminder Is Successfully Saved", Toast.LENGTH_LONG).show(); 

} 

更改insertEntry()方法與此一

或使用該

newValues.put("admin_name", userName); 
newValues.put("admin_phone", password); 
+0

你是maseeha – sajjan

相關問題