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)
5
  • 2
    Show us your Insert into please Commented Jun 30, 2015 at 15:35
  • 2
    INSERT INTO prospectos(,escobedo,gurrola,cesar,Guec) VALUES (?,?,?,?,?) You forgot to add the first field name. Here: (,escobedo. No, wait. You completely messed the insert: you are inserting the VALUES where the FIELD LIST has to (optionally) go. The VALUES are those funny ? you have in the insert. And must be passed using a String array. Commented Jun 30, 2015 at 15:36
  • database.insert("prospectos",null,altaProspecto); bd.close(); Toast.makeText(this, "Se Cargaron los Datos del Prospecto,",+ Toast.LENGTH_LONG).show(); here is the sql command or do you want the entire method? Commented Jun 30, 2015 at 15:38
  • The problem is with the INSERT code, not with the CREATE TABLE. Commented Jun 30, 2015 at 15:39
  • The problem is in content values creation probably, in altoProspecto. Commented Jun 30, 2015 at 15:45

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.