插入SQLite数据库的android [英] Insert in SQLite Database android
问题描述
在Android上即时通讯新。我有一些麻烦与数据库中插入语句,当运行应用程序的IM值尚未插入。请有人可以帮助..
公共类DatabaseAdapter扩展SQLiteOpenHelper {
//数据库属性
公共静态最后弦乐DB_NAME =MoneyManagerSystemTr;
公共静态最终诠释DB_VERSION = 1;//属性表公共静态最后弦乐TABLE_ACCOUNT =account_table;//账户表
公共静态最后弦乐KEY_BANKNAME =BANKNAME;
公共静态最后弦乐为key_type =类型;
公共静态最后弦乐KEY_ACCNUM =accnum;
公共静态最后弦乐KEY_BALANCE =平衡;
公共静态最后弦乐KEY_EXPIRYDATE =expirydate;@覆盖
公共无效的onCreate(SQLiteDatabase DB){
字符串AccountTable =创建表如果不存在+ TABLE_ACCOUNT +(+ BaseColumns._ID +整数主键自动增量
+ KEY_BANKNAME +文本不为空,
+为key_type +文字
+ KEY_ACCNUM +文字
+ KEY_BALANCE +文字
+ KEY_EXPIRYDATE +文本);; db.execSQL(AccountTable);字符串ROW1 =INSERT INTO+ TABLE_ACCOUNT +VALUES('现金','','',0,'');;
db.execSQL(ROW1); 字符串ROW2 =INSERT INTO+ TABLE_ACCOUNT +VALUES('银行账户','','',0,'');;
db.execSQL(ROW2); 字符串ROW3 =INSERT INTO+ TABLE_ACCOUNT +VALUES('信用卡','','',0,'');;
db.execSQL(ROW3);
这插入语句删除分号和周围添加引号0:
字符串ROW1 =INSERT INTO+ TABLE_ACCOUNT +(
+ KEY_BANKNAME +,+为key_type +,
+ KEY_ACCNUM +,+ KEY_BALANCE +,
+ KEY_EXPIRYDATE +)的值(现金','','','0','');
db.execSQL(ROW1);
更重要的是,在听取建议<一href=\"http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#execSQL%28java.lang.String%29\"相对=nofollow> execSQL(),并使用<一个href=\"http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#insert%28java.lang.String,%20java.lang.String,%20android.content.ContentValues%29\"相对=nofollow>插入()代替
im new on Android. I have some trouble with the insert statement in the database, when im running the application the values have not been inserted. Please someone can help..
public class DatabaseAdapter extends SQLiteOpenHelper {
// Database attributes
public static final String DB_NAME = "MoneyManagerSystemTr";
public static final int DB_VERSION = 1;
// Table attributes
public static final String TABLE_ACCOUNT = "account_table";
//Account Table
public static final String KEY_BANKNAME ="bankname";
public static final String KEY_TYPE = "type";
public static final String KEY_ACCNUM = "accnum";
public static final String KEY_BALANCE = "balance";
public static final String KEY_EXPIRYDATE = "expirydate";
@Override
public void onCreate(SQLiteDatabase db) {
String AccountTable = "create table if not exists " + TABLE_ACCOUNT + " ( " + BaseColumns._ID + " integer primary key autoincrement, "
+ KEY_BANKNAME + " text not null, "
+ KEY_TYPE + " text, "
+ KEY_ACCNUM + " text, "
+ KEY_BALANCE + " text, "
+ KEY_EXPIRYDATE + " text);";
db.execSQL(AccountTable);
String ROW1 = "INSERT INTO " + TABLE_ACCOUNT + " Values ('Cash','','',0, '');";
db.execSQL(ROW1);
String ROW2 = "INSERT INTO " + TABLE_ACCOUNT + " Values ('Bank Account','','',0, '');";
db.execSQL(ROW2);
String ROW3 = "INSERT INTO " + TABLE_ACCOUNT + " Values ('Credit Card','','',0, '');";
db.execSQL(ROW3);
Remove the semicolons from your insert statements and add quotes around 0:
String ROW1 = "INSERT INTO " + TABLE_ACCOUNT + " ("
+ KEY_BANKNAME + ", " + KEY_TYPE + ", "
+ KEY_ACCNUM + ", " + KEY_BALANCE + ", "
+ KEY_EXPIRYDATE + ") Values ('Cash', '', '', '0', '')";
db.execSQL(ROW1);
Better yet, heed the suggestion at execSQL() and use insert() instead.
这篇关于插入SQLite数据库的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!