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});

     }
        }
4

1 に答える 1

1

キーワード「テーブル」とテーブル名自体の間にスペースを追加する必要があると思います。

 create tableLOGINDETAILS

上記は、クエリと見なされると意味がありません。実際にはこのように表示されるはずですが、

create table LOGINDETAILS

したがって、スペースを追加すると、問題が解決するはずです。これを試して、

"create table"   +" "


+      "LOGINDETAILS"   
+      "(" 
+       " ID "   
+       "integer primary key autoincrement,"     
+   
        "  USERNAME   text   ,   PASSWORD    text   ,   EMPLOYEE_CODE    text   ,
       MOBILE integer  );"   ;
于 2013-08-16T06:57:01.953 に答える