由网友(君醉相思.)分享简介:在Android上即时通讯新。我有一些麻烦与数据库中插入语句,当运行应用程序的IM值尚未插入。请有人可以帮助.. 公共类DatabaseAdapter扩展SQLiteOpenHelper {//数据库属性公共静态最后弦乐DB_NAME =MoneyManagerSystemTr;公共静态最终诠释DB_VERSION...![Android开发 SQLiteDatabase的使用一](https://p.xsw88.cn/allimgs/daicuo/20230907/6817.png)
在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);
![Android开发 SQLiteDatabase的使用一](https://p.xsw88.cn/allimgs/daicuo/20230907/6817.png)
更重要的是,在听取建议 execSQL(),并使用插入()代替
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.
相关推荐
最新文章