下面是用於創建表遊客的商店名稱和地點ADRESS將值插入到SQLite數據庫時出錯?任何人都可以解決這個問題嗎?
公共類DbFav {
/** for database */
static final String DataBaseName = "Favdb";
/** for register table */
static final String favtable = "Visiters";
static final String VisitID = "visitid";
static final String ColNam="Name";
static final String ColAdd="Address";
public static final int DATABASE_VERSION = 3;
private static final String REGISTER_TABLE_CREATE ="Create table " + favtable + "("+VisitID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + ColNam+ " VARCHAR(15)," + ColAdd+ " VARCHAR(15)) ";
private final Context context; //for the linkage of the database wid the app
private DatabaseHelper DBHelper;
private SQLiteDatabase db;
public DbFav(Context ctx){
Log.i("test****", "**test***");
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}
private static class DatabaseHelper extends SQLiteOpenHelper{
public DatabaseHelper(Context context){
//super(context, DataBaseName , null, DATABASE_VERSION);
super(context, DataBaseName, null, DATABASE_VERSION);
Log.i("context","context");
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL(REGISTER_TABLE_CREATE);
//db.execSQL(SEARCH_TABLE_CREATE);
Log.i("************", "table created");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { //for update
// TODO Auto-generated method stub
Log.w("tag", "Upgrading database from version " + oldVersion + " to "+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + favtable);
onCreate(db);
}
}
public DbFav open() throws SQLException{
db = DBHelper.getWritableDatabase();
Log.i("open", "message");
return this;
}
public void close(){
DBHelper.close();
}
public long insert(String Name,String Address) {
Log.i("**** suruchitest **** ","*** test ***");
ContentValues initialValues = new ContentValues();
initialValues.put(ColNam,Name); //key , value
initialValues.put(ColAdd,Address);
Log.i("Values Inserted","Values are inserted");
return db.insert(favtable, null, initialValues);
值數據庫編碼從下方編碼保存到DB這給參觀者包含除外無上校命名(名稱,地址)
get_place=trname.getText().toString();
get_add=tradd.getText().toString();
db.open();
db.insert(get_place,get_add);
db.close();
Error inserting Name=KT Royal Hotel Sangrur Address=Nankiana Chowk, Patiala Bypass Road, Sangrur, Punjab 148001, India android.database.sqlite.SQLiteDatatypeMismatchException: datatype mismatch (code 20)
請把你這裏的錯誤logcat中...... – sushildlh
我不知道,如果VARCHAR採用的是Android的SQLite的數據類型。 – allancth
@allancth varchar是一個數據類型。沒有logcat錯誤很難找出錯誤。 – sushildlh