问题描述
我是新来SqlLite数据库。我一直在使用创建的数据库 SqlLite数据库浏览器
和路径保存它在Android应用程序项目文件夹的src / COM /例子/你好/数据库/
搜索结果
我也创建表了。现在,当我试图运行code,它是示值误差没有这样的表中找到。结果
我的code是如下:
公共类数据库处理器扩展SQLiteOpenHelper { 私有静态最终诠释DATABASE_VERSION = 3;
私有静态最后弦乐DATABASE_NAME =db_admin; 公共数据库处理器(上下文的背景下){
超(背景下,DATABASE_NAME,空,DATABASE_VERSION);
} @覆盖
公共无效的onCreate(SQLiteDatabase DB){ } //数据库升级
@覆盖
公共无效onUpgrade(SQLiteDatabase分贝,INT oldVersion,诠释静态网页){ } //添加用户响应时,他/她尝试的问题...
无效addUserResponse(UserResponse响应){
SQLiteDatabase分贝= this.getWritableDatabase(); ContentValues值=新ContentValues();
values.put(QID,response.getQId());
values.put(OptionId,response.getOptionId());
values.put(Responsedate,response.getResponseDate()); //插入行
db.insert(tblUserResponse,空,价值);
db.close();
}
}
插入值:
数据库处理器DB =新的数据库处理器(本); db.addUserResponse(新UserResponse(1,1,你好));
db.addUserResponse(新UserResponse(2,1,你好));
db.addUserResponse(新UserResponse(3,3,你好));
db.addUserResponse(新UserResponse(4,2,你好));
该数据库存储在/data/data/your.app.name/databases/。所以可能尝试运行您的code保持你的外部创建的数据库在这个位置。但我认为,如果你不植根你不能访问这个位置。
I am new to SqlLite Database. I have created Database using SqlLite Database Browser
and saved it in Android App Project Folder in path src/com/example/hello/databases/
I have also created tables already. Now, When I am trying to run code, It is showing error no such table found.
My code is as below :
public class DatabaseHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 3;
private static final String DATABASE_NAME = "db_admin";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
}
// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
// Adding User Response When He/She attempts Questions...
void addUserResponse(UserResponse response) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("QId", response.getQId());
values.put("OptionId", response.getOptionId());
values.put("Responsedate", response.getResponseDate());
// Inserting Row
db.insert("tblUserResponse", null, values);
db.close();
}
}
Inserting values as :
DatabaseHandler db = new DatabaseHandler(this);
db.addUserResponse(new UserResponse("1", "1", "hello"));
db.addUserResponse(new UserResponse("2", "1", "hello"));
db.addUserResponse(new UserResponse("3", "3", "hello"));
db.addUserResponse(new UserResponse("4", "2", "hello"));
The databases are stored in /data/data/your.app.name/databases/. So probably try running your code keeping your externally created db in this location. But I think you cant access this location if you are not rooted.
这篇关于android.database.sqlite.SQLiteException:没有这样的表:tblUserResponse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!