Pergunta

I was just About to create a Sample for Proper Understanding on how the Hello Android for ORMLite works in Android.

    public class SchoolDataBean {


// id is generated by the database and set on the object automagically
@DatabaseField(generatedId = true)
int rollNo;
@DatabaseField(index = true)
String name;
@DatabaseField
String gender;
@DatabaseField
boolean presence;

public SchoolDataBean() {
//required by ORM :)
}

public void setRollNo(int rollNo) {
    this.rollNo = rollNo;
}

public void setName(String name) {
    this.name = name;
}

public void setGender(String gender) {
    this.gender = gender;
}

public void setPresence(boolean presence) {
    this.presence = presence;
}

}

In the Database Helper when I try Inserting the initial Values and creating the table with

      SchoolDataBean schoolDataSecond = new SchoolDataBean();
    schoolDataSecond.setName("Ram");
    schoolDataSecond.setGender("F");
    schoolDataSecond.setPresence(true);
    schoolDataSecond.setRollNo(2);
    dao.create(schoolDataSecond);

I get this exception from the ORMLite Library as

  sqlite returned: error code = 1, msg = duplicate column name: gender

   java.sql.SQLException: SQL statement failed: CREATE TABLE `schooldata` (`rollNo` INTEGER PRIMARY KEY AUTOINCREMENT , `name` VARCHAR , `gender` VARCHAR , `gender` VARCHAR , `presence` SMALLINT ) 

thanks everyone.

      The Exception seems to be caused at this line
        TableUtils.createTable(connectionSource, SchoolDataBean.class);
Foi útil?

Solução

Actually i didn't realize that I needed to check the Config.txt for Column names too, there it was, two similar column names which caused this duplication problem.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top