简体   繁体   English

E/SQLiteLog: (1) near "-": android app 中插入数据时出现语法错误

[英]E/SQLiteLog: (1) near "-": syntax error when insert data in android app

I'm getting this error in my app when I try to write to database E/SQLiteLog: (1) near "-": syntax error please can you help me... Here is my code for SQLite databse.当我尝试写入数据库 E/SQLiteLog 时,我在我的应用程序中收到此错误:(1)“-”附近:语法错误,请您帮帮我...这是我的 SQLite 数据库代码。 I am attaching the complete code for database class here我在这里附上数据库类的完整代码

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) {

    }
}

Replace Your addClientMethod with it.用它替换你的 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...");

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “ INSERT”附近的SQLiteLog错误(1):语法错误 - SQLiteLog Error (1) near “INSERT”: syntax error ANDROID STUDIO / SQLiteLog:(1)在“LIMIT”附近:语法错误 - ANDROID STUDIO / SQLiteLog: (1) near “LIMIT”: syntax error SQLiteLog:(1)在“ *”附近:语法错误 - SQLiteLog﹕ (1) near “*”: syntax error 数据库不存储数据。 我从Android Studio日志中得到“SQLiteLog:(1)near”Name“:语法错误” - Database does not store data. I get the “SQLiteLog: (1) near ”Name“: syntax error” from Android Studio log Android - SQLiteException:near“=”:语法错误(代码1) - Android - SQLiteException: near “=”: syntax error (code 1) E/SQLiteLog: (1) 表 Estudiantes 在 android 中没有名为 calificacion 的列 - E/SQLiteLog: (1) table Estudiantes has no column named calificacion in android “”附近:使用 android studio 的 SQL 中的语法错误 - near "": syntax error in SQL with android studio E/SQLiteLog: (1) 没有这样的列:100 - E/SQLiteLog: (1) no such column: 100 E/SQLiteLog: (1) no such column: rushi - E/SQLiteLog: (1) no such column: rushi 尝试从SQLite数据库更新数据时出现SQL错误或数据库丢失(在“。”附近:语法错误)的Java错误 - SQL error or missing database (near “.”: syntax error) error in java when trying to update data from sqlite databse
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM