2016-05-08 2 views
-1

データベースに書き込もうとすると、このエラーが発生します。 :構文エラー あなたは私を助けることができます... ここにSQLiteデータベースのための私のコードです。ここではデータベースクラスのコード全体を添付しますE/SQLiteLog:(1)near " - ":アンドロイドアプリにデータを挿入するときの構文エラー

import android.content.ContentValues; 
import android.content.Context; 
import android.database.sqlite.SQLiteDatabase; 
import android.database.sqlite.SQLiteOpenHelper; 
import android.util.Log; 

/** 
* Created by TOSHIBA on 01/05/2016. 
*/ 

// CREATION DATABASE 

public class DatabaseHelper extends SQLiteOpenHelper { 
    private SQLiteDatabase db; 

    private static final String DATABASE_NAME = "QuickTowing.db"; 

    private static final String QUERY = 
      "CREATE TABLE "+ TablesDB.NewClientInfo.TABLE_NAME+"("+ TablesDB.NewClientInfo.COL_1+" INTEGER PRIMARY KEY AUTOINCREMENT," 
        + TablesDB.NewClientInfo.COL_2+" TEXT,"+ TablesDB.NewClientInfo.COL_3+" TEXT,"+ TablesDB.NewClientInfo.COL_4+" TEXT," 
        + TablesDB.NewClientInfo.COL_5+" INTEGER,"+ TablesDB.NewClientInfo.COL_6+" TEXT,"+ TablesDB.NewClientInfo.COL_7+" TEXT," 
        + TablesDB.NewClientInfo.COL_8+" TEXT);"; 

    //CREATE DATABASE 
    public DatabaseHelper(Context context) { 

     super(context, DATABASE_NAME, null, 1); 
     Log.e("Database operations","database created/opened... "); 
    } 

    //CREATE TABLECLIENT 
    @Override 
    public void onCreate(SQLiteDatabase db) { 

     db.execSQL(QUERY); 
     Log.e("Database operations","Table created..."); 
    } 

    //ADD CLIENT 
    public void addClientInformations (Integer CIN,String name, String surname,String email,Integer phone,String password, String vehType,String vehModel, SQLiteDatabase db){ 

     ContentValues contentValues = new ContentValues(); 
     contentValues.put(TablesDB.NewClientInfo.COL_1,CIN); 
     contentValues.put(TablesDB.NewClientInfo.COL_2,name); 
     contentValues.put(TablesDB.NewClientInfo.COL_3,surname); 
     contentValues.put(TablesDB.NewClientInfo.COL_4,email); 
     contentValues.put(TablesDB.NewClientInfo.COL_5,phone); 
     contentValues.put(TablesDB.NewClientInfo.COL_6,password); 
     contentValues.put(TablesDB.NewClientInfo.COL_7,vehType); 
     contentValues.put(TablesDB.NewClientInfo.COL_8,vehModel); 
     db.insert(TablesDB.NewClientInfo.TABLE_NAME,null,contentValues); 

     Log.e("Database operations","One row inserted..."); 

    } 

    @Override 
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 

    } 
} 
+0

あなたの投稿を編集し、このエラーが発生している箇所のコードセクションを含めてください。コードをコピーして貼り付け、それを選択してCtrl + Kを押します。 – Arc676

+1

'-'でテーブル名またはカラム名を使用する場合、バックティック –

+0

...または角括弧(' [your-attribute-name] ')で名前をエスケープする必要があります –

答えて

-1

addClientMethodをそれに置き換えます。

public void addClientInformations (Integer CIN,String name, String surname,String email,Integer phone,String password, String vehType,String vehModel){ 

     SQLiteDatabase db=getWritableDatabase(); 


     ContentValues contentValues = new ContentValues(); 
     contentValues.put(TablesDB.NewClientInfo.COL_1,CIN); 
     contentValues.put(TablesDB.NewClientInfo.COL_2,name); 
     contentValues.put(TablesDB.NewClientInfo.COL_3,surname); 
     contentValues.put(TablesDB.NewClientInfo.COL_4,email); 
     contentValues.put(TablesDB.NewClientInfo.COL_5,phone); 
     contentValues.put(TablesDB.NewClientInfo.COL_6,password); 
     contentValues.put(TablesDB.NewClientInfo.COL_7,vehType); 
     contentValues.put(TablesDB.NewClientInfo.COL_8,vehModel); 
     db.insert(TablesDB.NewClientInfo.TABLE_NAME,null,contentValues); 

     Log.e("Database operations","One row inserted..."); 

    } 
関連する問題