2013-08-16 145 views
0

嗨我試圖創建一個活動,包括數據庫,但在運行應用程序時,它顯示一些語法錯誤,並突然停止。我試圖調整語法上的空間,但它不起作用,我需要一些建議來克服我的錯誤。我給下面活動停止

08-16 06:47:55.830: E/AndroidRuntime(1718): FATAL EXCEPTION: main 

08-16 06:47:55.830: E/AndroidRuntime(1718): android.database.sqlite.SQLiteException: near "tableLOGINDETAILS": syntax error (code 1): , while compiling: create tableLOGINDETAILS(ID integer primary key autoincrement, USERNAME text , PASSWORD text , EMPLOYEE_CODE text , MOBILE integer ); 

08-16 06:47:55.830: E/AndroidRuntime(1718):  at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) 

08-16 06:47:55.830: E/AndroidRuntime(1718):  at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882) 

08-16 06:47:55.830: E/AndroidRuntime(1718):  at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493) 

這個我日誌貓代碼

static final String DATABASE_NAME="LOGINDETAILS.db"; 
static final int DATABASE_VERSION=1; 
public static final int NAME_COLUMN=1; 

static final String DATABASE_CREATE = "create table" 
// create a Sql query for database  

+  "LOGINDETAILS" 
+  "(" 
+  " ID " 
+  "integer primary key autoincrement,"  
+ 
     " USERNAME text , PASSWORD text , EMPLOYEE_CODE text , 
     MOBILE integer );" ; 

public SQLiteDatabase db; 
private final Context context; 
private DataBaseHelper dbHelper; 
public LoginDataBaseAdapter(Context _context) 
{ 
    context=_context; 
    dbHelper=new DataBaseHelper(_context, DATABASE_NAME, null, 
     DATABASE_VERSION); 

} 

public LoginDataBaseAdapter open()throws SQLException 
{ 
    db=dbHelper.getWritableDatabase(); 
    return this; 
} 
     public void close() 
     { 
     db.close(); 
    } 

     public SQLiteDatabase getDatabaseInstance() 
     { 
    return db; 
     } 

     public void insertEntry(String User_name,String Password,String Emp_code,String 
     Mob) 
    { 
     ContentValues newValues=new ContentValues(); 
    //Assign values for each column 
     newValues.put("USERNAME", User_name); 
     newValues.put("PASSWORD", Password); 
     newValues.put("EMPLOYEE_CODE", Emp_code); 
     newValues.put("MOBILE", Mob); 

     //Insert the row into the table 

     db.insert("LOGINDETAILS", null, newValues); 
     Toast.makeText(context, "User Info Saved", Toast.LENGTH_LONG).show(); 

     } 

     //Method to delete a record of username 

     public int deleteEntry(String User_name) 
     { 
    String where ="USERNAME=?"; 
    int numberOFEntriesDeleted=db.delete("LOGINDETAILS", where,new String[] 
     {User_name}); 
    Toast.makeText(context, "No of entry deleted successfully : 
     "+numberOFEntriesDeleted, Toast.LENGTH_LONG).show(); 
     return numberOFEntriesDeleted; 
     } 
    // method to get the password of the username 

     public String getSingleEntry(String User_name) 
      { 
    Cursor cursor=db.query("LOGINDETAILS", null, "USERNAME=?", new String[] 
     {User_name},null, null, null); 
     if(cursor.getCount()<1) //No user exist 
    return "NOT EXIST"; 
     cursor.moveToFirst(); 
     String Password=cursor.getString(cursor.getColumnIndex("PASSWORD")); 
     return Password; 
       } 

      // Method to update an existing record 
      public void updateEntry(String User_name,String Password) 
      { 
     //Create object of content values 
      ContentValues updatedValues=new ContentValues(); 
      // Assign values for each item 
     updatedValues.put("USERNAME", User_name); 
     updatedValues.put("PASSWORD", Password); 

      String where="USERNAME=?"; 
      db.update("LOGINDETAILS", updatedValues, where, new String[] 
     {User_name}); 

    } 
     } 
+0

你在'table'和'LOGINDETAILS'之間缺少一個空格。 –

回答

1

我認爲你需要關鍵字「表」和表名本身之間添加一個空格。

create tableLOGINDETAILS 

上述方法在被視爲查詢時沒有意義。它實際上應該看起來像這樣,

create table LOGINDETAILS 

因此,添加一個空間,它應該可以解決問題。試試這個吧,

"create table" +" " 


+  "LOGINDETAILS" 
+  "(" 
+  " ID " 
+  "integer primary key autoincrement,"  
+ 
     " USERNAME text , PASSWORD text , EMPLOYEE_CODE text , 
     MOBILE integer );" ;