使用OrmLiteSqliteOpenHelper类android的Sqlite数据库中的alter表中存在问题
你好,朋友,我想在我的应用程序中添加一个新的专栏,下面是我的代码使用OrmLiteSqliteOpenHelper类android的Sqlite数据库中的alter表中存在问题,android,sqlite,android-sqlite,upgrade,alter,Android,Sqlite,Android Sqlite,Upgrade,Alter,你好,朋友,我想在我的应用程序中添加一个新的专栏,下面是我的代码 public class DatabaseConnectionAPI extends OrmLiteSqliteOpenHelper { public DatabaseConnectionAPI(Context context) { super(context, DB_PATH + DB_NAME, null, 1); this.myContext = context; }
public class DatabaseConnectionAPI extends OrmLiteSqliteOpenHelper {
public DatabaseConnectionAPI(Context context) {
super(context, DB_PATH + DB_NAME, null, 1);
this.myContext = context;
}
public void openDataBase() throws SQLException {
try {
db.close();
} catch (Exception e) {
System.out.println("no database connected to close");
}
// Open the database
String myPath = DB_PATH + DB_NAME;
db = SQLiteDatabase.openDatabase(myPath, null,
SQLiteDatabase.OPEN_READWRITE);
onUpgrade(db, connectionSource, 1, 2);
System.out.println("Databse opened...." + db);
}
@Override
public synchronized void close() {
if (db != null)
db.close();
super.close();
}
@Override
public void onCreate(SQLiteDatabase arg0, ConnectionSource arg1) {
System.out.println("Create DB");
try {
TableUtils.createTable(connectionSource, Property_Master.class);
} catch (SQLException e) {
Log.e(DatabaseConnectionAPI.class.getName(), "Can't create database", e);
throw new RuntimeException(e);
} catch (java.sql.SQLException e) {
e.printStackTrace();
}
}
@Override
public void onUpgrade(SQLiteDatabase arg0, ConnectionSource arg1, int arg2,
int arg3) {
try {
ArrayList<String> allSql = new ArrayList<String>();
switch(arg2)
{
case 1:
allSql.add("ALTER TABLE " + "property_master" + " ADD COLUMN " + " p_type " + "VARCHAR");
}
for (String sql : allSql) {
db.execSQL(sql);
}
} catch (SQLException e) {
Log.e(DatabaseConnectionAPI.class.getName(), "exception during onUpgrade", e);
throw new RuntimeException(e);
}
}
}
你知道怎么解决吗?你知道“重复列名”是什么意思吗?@CL-ya数据库中已经存在相同的列,但我第一次修改了它,但仍然显示上面的错误?然后它第一次就已经存在了。
android.database.sqlite.SQLiteException: duplicate column name: p_type: ALTER TABLE property_master ADD COLUMN p_type VARCHAR