I am trying to create manually table after one table wallet default created. now when i am trying to create new one table from string table not created. please help me about this. My code is below for database.
public class MyDatabase {
public static final String KEY_ROWID = "_id";
public static final String KEY_DETAIL = "detail";
public static final String KEY_AMOUNT = "amount";
public static final String KEY_DATE = "date";
private static final String DB_NAME = "quickdata";
private static final String DB_TABLE = "Wallet";
private static final String DB_TABLEE = "Wallettw";
private static int DB_VIRSION = 1;
private DBHelper ourHelper;
private final Context ourContext;
private SQLiteDatabase ourDatabase;
private static class DBHelper extends SQLiteOpenHelper {
/* public DBHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
}*/
public DBHelper(Context context) {
super(context, DB_NAME, null, DB_VIRSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + DB_TABLE + " (" +
KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
KEY_DETAIL + " TEXT NOT NULL, " +
KEY_AMOUNT + " NUMBER NOT NULL, " +
KEY_DATE + " TEXT NOT NULL);"
);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + DB_TABLE);
onCreate(db);
}
}
public MyDatabase(Context c) {
ourContext = c;
}
public MyDatabase open() {
ourHelper = new DBHelper(ourContext);
ourDatabase = ourHelper.getWritableDatabase();
return this;
}
public void close() {
ourHelper.close();
}
/////////HEAR I WANT TO CREATE A TABLE IF POSSIBLE/////////////////// public void createCategory(String s)throws SQLException {
ourDatabase.execSQL("DROP TABLE IF EXISTS "+s);
ourDatabase.execSQL("CREATE TABLE " + s + " (" +
KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
KEY_DETAIL + " TEXT NOT NULL, " +
KEY_AMOUNT + " NUMBER NOT NULL, " +
KEY_DATE + " TEXT NOT NULL);"
);
}
}
Aucun commentaire:
Enregistrer un commentaire