gpt4 book ai didi

android - 插入 SQLite 数据库 android

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:18:03 24 4
gpt4 key购买 nike

我是 Android 上的新手。我在数据库中插入语句时遇到一些问题,当我运行应用程序时,尚未插入值。请有人帮忙..

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);

最佳答案

您可以使用 ContentValues 插入到您的数据库中。

SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(COL_NAME, VALUE);
values.put(COL_NAME, VALUE);

// Inserting Row
db.insert(YOUR_TABLE, null, values);

关于android - 插入 SQLite 数据库 android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13191816/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com