-1

Hey when I'm trying to insert in the mysql Database.. Then I get the error:

E/SQLiteDatabase: Error inserting userVorname=test userAnrede=Herr userPw=test userPraxisAdresszusatz= userEmail=test userTel=016722435 userPraxisPlz= userPraxisName= userPraxisTel= userPraxisStadt= userName=test userPraxisAdresse= userTitel=
              android.database.sqlite.SQLiteException: table UserDatabase has no column named userName (code 1): , while compiling: INSERT INTO UserDatabase(userVorname,userAnrede,userPw,userPraxisAdresszusatz,userEmail,userTel,userPraxisPlz,userPraxisName,userPraxisTel,userPraxisStadt,userName,userPraxisAdresse,userTitel) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)

I know that the Compiler says that there is no column named userName but in my Manager i setted it. And I found no missing commas or something like this.. I hope you guys can help me out..

public class UserDatenbankManager extends SQLiteOpenHelper {
    private static final String DB_NAME = "UserDatabase";
    private static final int DB_VERSION = 1;
    private static final int COL0 = 0;
    private static final String COL1 = "userName";
    private static final String COL2 = "userVorname";
    private static final String COL3 = "userAnrede";
    private static final String COL4 = "userTitel";
    private static final String COL5 = "userTel";
    private static final String COL6 = "userEmail";
    private static final String COL7 = "userPraxisName";
    private static final String COL8 = "userPraxisAdresse";
    private static final String COL9 = "userPraxisPlz";
    private static final String COL10 = "userPraxisStadt";
    private static final String COL11 = "userPraxisTel";
    private static final String COL12 = "userPraxisAdresszusatz";
    private static final String COL13 = "userPw";
    private static final String SQL_CREATE =
            "CREATE TABLE " + DB_NAME + "(" + //COL0 + "INTEGER PRIMARY KEY 
    AUTOINCREMENT, " +
                    COL1 + " TEXT, " + COL2 + " TEXT, " + COL3 + " TEXT, " +
                    COL4 + " TEXT, " + COL5 + " TEXT, " + COL6 + " TEXT, " +
                    COL7 + " TEXT, " + COL8 + " TEXT, " + COL9 + " TEXT, " +
                    COL10 + " TEXT, " + COL11 + " TEXT, " + COL12 + " TEXT, " +
                    COL13 + " TEXT);";


    public void insertUser(String name, String vorname, String anrede, String 
    titel,
                           String tel, String mail, String pName, String 
    pAdresse,
                           String pPLZ, String pStadt, String pTel, String 
    pAdrZs,
                           String pw)
    {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        //contentValues.put(COL0, new Integer());
        contentValues.put(COL1, name);
        contentValues.put(COL2, vorname);
        contentValues.put(COL3, anrede);
        contentValues.put(COL4, titel);
        contentValues.put(COL5, tel);
        contentValues.put(COL6, mail);
        contentValues.put(COL7, pName);
        contentValues.put(COL8, pAdresse);
        contentValues.put(COL9, pPLZ);
        contentValues.put(COL10, pStadt);
        contentValues.put(COL11, pTel);
        contentValues.put(COL12, pAdrZs);
        contentValues.put(COL13, pw);
        db.insert(DB_NAME, null, contentValues);
    }
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

0

Please use the following sql script to create your table. I think your table was not created due to the error in your sql create query.

 private static final String COL0 = "id";

 private static final String SQL_CREATE =
    "CREATE TABLE " + DB_NAME + " (" + COL0 + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
            COL1 + " TEXT, " + COL2 + " TEXT, " + COL3 + " TEXT, " +
            COL4 + " TEXT, " + COL5 + " TEXT, " + COL6 + " TEXT, " +
            COL7 + " TEXT, " + COL8 + " TEXT, " + COL9 + " TEXT, " +
            COL10 + " TEXT, " + COL11 + " TEXT, " + COL12 + " TEXT, " +
            COL13 + " TEXT);";

There was no space between COL0 and INTEGER PRIMARY KEY. I think that was the problem. COL0 has an integer value which needs to be an String named id as far as I could understand from your code.

Please let me know if that fixed your issue. Thanks.

Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98