[英]trying to call user_id from sqlite
I'm trying to call user_id from sqlite database but I get this error 我试图从sqlite数据库调用user_id但是我收到此错误
android.database.sqlite.SQLiteException: unknown error (code 0 SQLITE_OK): Queries can be performed using SQLiteDatabase query or rawQuery methods only.
android.database.sqlite.SQLiteException:未知错误(代码0 SQLITE_OK):只能使用SQLiteDatabase查询或rawQuery方法执行查询。 at android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount(Native Method)
在android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount(本机方法)
public Database user_id(){
SQLiteDatabase db = getReadableDatabase();
String query = String.format("SELECT user_id FROM OrderDetails ;");
db.execSQL(query);
Cursor c = db.rawQuery(query, null);
if (c != null && c.moveToFirst()) {
c.moveToFirst();
}
return user_id();
}
Please don't recommend another solution because I'm stuck with this for more than a day and I tried almost all solutions represented in stackoverflow and online 请不要推荐其他解决方案,因为我已经坚持了一天以上,我尝试了几乎所有在stackoverflow和online中表示的解决方案
From: https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase#execSQL(java.lang.String) 来自: https : //developer.android.com/reference/android/database/sqlite/SQLiteDatabase#execSQL(java.lang.String)
public void execSQL (String sql)
public void execSQL(String sql)
Execute a single SQL statement that is NOT a SELECT or any other SQL statement that returns data.执行一个非SELECT的SQL语句或任何其他返回数据的SQL语句。
So remove this line: 所以删除这一行:
db.execSQL(query);
The method execSQL()
is not used to execute queries that fetch rows, like SELECT statements. 方法
execSQL()
不用于执行获取行的查询,如SELECT语句。 You can use it with INSERT, UPDATE, CREATE, etc. 您可以将它与INSERT,UPDATE,CREATE等一起使用。
Also, I think that you want to return the user's ids as a Cursor
, right? 另外,我认为你想将用户的id作为
Cursor
,对吧?
So why: 所以为什么:
public Database user_id()
this returns a Database object (whatever this is). 这将返回一个Database对象(不管这是什么)。
Change the method to this: 将方法更改为:
public Cursor user_id(){
SQLiteDatabase db = getReadableDatabase();
String query = "SELECT user_id FROM OrderDetails";
Cursor c = db.rawQuery(query, null);
return c;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.