专栏不存在 - 为什么?

时间:2018-03-17 17:54:30

标签: java android sqlite

嘿,当我试图插入mysql数据库时..然后我收到错误:

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 (?,?,?,?,?,?,?,?,?,?,?,?,?)

我知道编译器说没有名为userName的列,但在我的经理中我设置了它。我发现没有丢失的逗号或类似的东西..我希望你们能帮助我......

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

1 个答案:

答案 0 :(得分:0)

请使用以下sql脚本创建表。我认为你的表是由于你的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);";

COL0INTEGER PRIMARY KEY之间没有空格。我认为这就是问题所在。 COL0有一个整数值,根据您的代码,我可以理解为String id

如果问题解决了,请告诉我。感谢。