[英]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.