- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在尝试在 android 中建立数据库时遇到问题,每次我登录时,日志猫都说没有这样的表。
public class DatabaseOnline extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "name";
private static final String TABLE_LOGIN = "online";
private static final String KEY_ID = "Registration_id";
private static final String KEY_NAME = "Name";
private static final String KEY_PASSWORD = "Password";
private static final String KEY_UNIQUEID = "unique_id";
public DatabaseOnline(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_LOGIN_TABLE = "CREATE TABLE " + TABLE_LOGIN + "("
+ KEY_NAME + " VARCHAR (255), " + KEY_PASSWORD
+ " VARCHAR (255), " + KEY_ID + " VARCHAR(255), "
+ KEY_UNIQUEID + " VARCHAR (255)" + ")";
db.execSQL(CREATE_LOGIN_TABLE);
}
public void addUser(String name, String password, String regId,
String unique_id) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_NAME, name); // Name
values.put(KEY_PASSWORD, password); // Email
values.put(KEY_ID, regId);
values.put(KEY_UNIQUEID, unique_id);
// Inserting Row
db.insert(TABLE_LOGIN, null, values);
db.close(); // Closing database connection
}
public int getRowCount() {
String countQuery = "SELECT * FROM " + TABLE_LOGIN;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
int rowCount = cursor.getCount();
db.close();
cursor.close();
// return row count
return rowCount;
}
/**
* Re crate database Delete all tables and create them again
* */
public void resetTables() {
SQLiteDatabase db = this.getWritableDatabase();
// Delete All Rows
db.delete(TABLE_LOGIN, null, null);
db.close();
}
}
问题是当我登录时:
DatabaseOnline db = new DatabaseOnline(getApplicationContext());
db.getWritableDatabase();
JSONObject json_user = json.getJSONObject("user");
System.out.println("unique id " + json_user.getString("unique_id"));
System.out.println("password " + json_user.getString("password"));
db.addUser(json_user.getString("name"),json_user.getString("password"),json_user.getString("regId"),json_user.getString("unique_id"));
Intent dashboard = new Intent(getApplicationContext(),Main.class);
dashboard.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(dashboard);
finish();
出现的是android没有创建数据库。这是日志猫:
11-20 21:42:15.162: E/SQLiteLog(1176): (1) no such table: online
11-20 21:42:15.282: E/SQLiteDatabase(1176): Error inserting unique_id=50a939dc9fa8a4.09780382 Name=v Registration_id=APA91bHnScWAF0xjtMjyHTvHx3ON6Eu_8on6kZUL5EvDmtAK8WDxwBVpNyMoapaTl0-ProAnY0m9VZbS-0OPeMshQkeU7ZOHlfI8tUAVJbeIgoe9sdL061ntJ8MnyglrLHK2BOWH2K1n Password=9e3669d19b675bd57058fd4664205d2a
11-20 21:42:15.282: E/SQLiteDatabase(1176): android.database.sqlite.SQLiteException: no such table: online (code 1): , while compiling: INSERT INTO online(unique_id,Name,Registration_id,Password) VALUES (?,?,?,?)
11-20 21:42:15.282: E/SQLiteDatabase(1176): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
11-20 21:42:15.282: E/SQLiteDatabase(1176): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
11-20 21:42:15.282: E/SQLiteDatabase(1176): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
11-20 21:42:15.282: E/SQLiteDatabase(1176): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
11-20 21:42:15.282: E/SQLiteDatabase(1176): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
11-20 21:42:15.282: E/SQLiteDatabase(1176): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
11-20 21:42:15.282: E/SQLiteDatabase(1176): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
11-20 21:42:15.282: E/SQLiteDatabase(1176): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
11-20 21:42:15.282: E/SQLiteDatabase(1176): at guc.edu.i.DatabaseOnline.addUser(DatabaseOnline.java:66)
11-20 21:42:15.282: E/SQLiteDatabase(1176): at guc.edu.i.Login.login(Login.java:199)
11-20 21:42:15.282: E/SQLiteDatabase(1176): at guc.edu.i.Login$7.run(Login.java:146)
11-20 21:42:15.282: E/SQLiteDatabase(1176): at java.lang.Thread.run(Thread.java:856)
最佳答案
这是第一次创建数据库吗?尝试改变
private static final int DATABASE_VERSION = 1;
到
private static final int DATABASE_VERSION = 2;
这将导致创建表并解决问题
关于android - 在 SQLite 中找不到这样的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13481356/
例如,我有一个父类Author: class Author { String name static hasMany = [ fiction: Book,
代码如下: dojo.query(subNav.navClass).forEach(function(node, index, arr){ if(dojo.style(node, 'd
我有一个带有 Id 和姓名的学生表和一个带有 Id 和 friend Id 的 Friends 表。我想加入这两个表并找到学生的 friend 。 例如,Ashley 的 friend 是 Saman
我通过互联网浏览,但仍未找到问题的答案。应该很容易: class Parent { String name Child child } 当我有一个 child 对象时,如何获得它的 paren
我正在尝试创建一个以 Firebase 作为我的后端的社交应用。现在我正面临如何(在哪里?)找到 friend 功能的问题。 我有每个用户的邮件地址。 我可以访问用户的电话也预订。 在传统的后端中,我
我主要想澄清以下几点: 1。有人告诉我,在 iOS 5 及以下版本中,如果您使用 Game Center 设置多人游戏,则“查找 Facebook 好友”(如与好友争夺战)的功能不是内置的,因此您需要
关于redis docker镜像ENTRYPOINT脚本 docker-entrypoint.sh : #!/bin/sh set -e # first arg is `-f` or `--some-
我是一名优秀的程序员,十分优秀!