这是我在 Stackoverflow 中的第一个问题,所以我想向大家问好;) 我有个问题。我正在尝试将变量中的数据插入 SQLite 数据库。 在android中,当你创建数据库时,你是在类OnCreate中完成的,所以你只能把 静态数据,那么如果我想将变量(经度或纬度)的 GPS 数据放在这里怎么办? 我想创建一个大数据库,以 1 秒的频率插入 GPS 的位置。 问候
SQLiteDatabase db = openOrCreateDatabase(Database.DB_NAME,
MODE_PRIVATE, null); db.execSQL(Database.DB_CREATE);
db.execSQL("INSERT INTO baza(id,LEFT_POSITION, RIGHT_POSITION, GPS,
TIME) values (" + "1" + "," + x + "," + y + "," + z + "," + c +");");
db.close();
最佳答案
The recommended method to create a new SQLite database is to create a subclass of SQLiteOpenHelper and override the onCreate() method, in which you can execute a SQLite command to create tables in the database.
...
You can then get an instance of your SQLiteOpenHelper implementation using the constructor you've defined. To write to and read from the database, call getWritableDatabase() and getReadableDatabase(), respectively. These both return a SQLiteDatabase object that represents the database and provides methods for SQLite operations.
关于android - 将动态数据从变量插入 SQLite (Android),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21027169/