2013-08-16 4 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

난 당신이 키워드 "표"와 TABLENAME 자체 사이에 공백을 추가 할 필요가 있다고 생각을합니다.

create tableLOGINDETAILS 

위의 내용은 쿼리로 간주 될 때 의미가 없습니다. 실제로 이렇게 보일 것입니다.

create table LOGINDETAILS 

그래서 공백을 추가하면 문제가 해결됩니다. 이것을 시도하십시오,

"create table" +" " 


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