JoeEl RedbouUrne
JoeEl RedbouUrne

Reputation: 33

Android SQLite syntax error SQLiteException (code 1)

The error I'm getting is SQLiteException: near ",": syntax error (code 1), and I cant figure where my mistake is. I´ve read some other questions with the same error and the answer they give is that it's a simple syntax error with a missing comma. However I've checked again and that doesn't seem to be my problem. I've included the code below.

public static final String prospectos="RegProspectos.db";
public static final int dbversion = 1;
public static final String tabla_prospectos="prospectos";
public static final String cm_NomProspec="NomProspec";
public static final String cm_ApProspec="ApProspec";
public static final String cm_AmProspec="AmProspec";
public static final String cm_RfcProspec="RfcProspec";
public static final String cm_TelCasa="TelCasa";
public static final String cm_TelOficina="TelOficina";

public adminProspec(Context context)
{super(context,prospectos, null, dbversion);}

@Override
public void onCreate(SQLiteDatabase db) {
    final String crea_tabla=
            "CREATE TABLE "+tabla_prospectos+"("
                    +cm_NomProspec+     " TEXT,"
                    +cm_ApProspec+      " TEXT,"
                    +cm_AmProspec+      " TEXT,"
                    +cm_RfcProspec +    " TEXT,"
                    +cm_TelCasa+        " TEXT,"
                    +cm_TelOficina+     " TEXT,"
                    +cm_UsrActReg+      " TEXT "+")";
    db.execSQL(crea_tabla); }

Here is my logcat output:

 06-30 11:15:18.083: E/SQLiteDatabase(1867): Error inserting = escobedo=escobedo gurrola=gurrola cesar=cesar Guec=Guec
06-30 11:15:18.083: E/SQLiteDatabase(1867): android.database.sqlite.SQLiteException: near ",": syntax error (code 1): , while compiling: INSERT INTO prospectos(,escobedo,gurrola,cesar,Guec) VALUES (?,?,?,?,?)
06-30 11:15:18.083: E/SQLiteDatabase(1867):     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
06-30 11:15:18.083: E/SQLiteDatabase(1867):     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)

Upvotes: 1

Views: 906

Answers (3)

JoeEl RedbouUrne
JoeEl RedbouUrne

Reputation: 33

thank you so much like you said the error where in the insert method, the problem i think, was that I were trying to insert values instead of fields correct me if I'm wrong, that's simple but i don't know how to explain it...

...sNomProspec.getText().toString();
...sApProspec.getText().toString();
...sAmProspec.getText().toString()


     altaProspecto.put(NomProspec, NomProspec);
             altaProspecto.put(ApProspec, ApProspec);
             altaProspecto.put(AmProspec, AmProspec);


     altaProspecto.put("NomProspec", sNomProspec.getText().toString());
             altaProspecto.put("ApProspec", sApProspec.getText().toString());
             altaProspecto.put("AmProspec", sAmProspec.getText().toString());

I just added the quotes and changed I corrected and now it works thanks a lot =D

Upvotes: 2

heloisasim
heloisasim

Reputation: 5016

You should use ContentValues to insert your data:

Example:

ContentValues contentValues = new ContentValues();
contentValues.put(cm_NomProspec, "nomProstect value");
contentValues.put(cm_ApProspec, "Prostect value");
contentValues.put(cm_RfcProspec, "pfProstect value");
database.insert(tabla_prospectos, null, contentValues);

bd.close(); 
Toast.makeText(this, "Se Cargaron los Datos del Prospecto,",+ Toast.LENGTH_LONG).show();

Upvotes: 0

Skizo-ozᴉʞS ツ
Skizo-ozᴉʞS ツ

Reputation: 20616

06-30 11:15:18.083: E/SQLiteDatabase(1867): android.database.sqlite.SQLiteException: near ",": syntax error (code 1): , while compiling: INSERT INTO prospectos(,escobedo,gurrola,cesar,Guec) VALUES (?,?,?,?,?)

This error is about an Insert that you do somewhere... You put a comma inside an Insert so your Insert should be like this :

INSERT INTO prospectos(escobedo,gurrola,cesar,Guec) VALUES (?,?,?,?,?)

Other issue that I'm seeing is that in your Insert you put 4 fields and on your values you put 5, you have to put the same values as fields you put. (I guess your ? values are something that you don't want to show to us, if it's not, you can't pass a ? to an Insert).

See SQLite - INSERT Query to know more about INSERT INTO.

Upvotes: 0

Related Questions