简体   繁体   English

试图从sqlite调用user_id

[英]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.

相关问题 如何获取保存在 USER_ID 中的数据? - How to get the data saved in a USER_ID? 休眠列'user_id'不能为null - Hibernate Column 'user_id' cannot be null 如何在实体更新中设置user_id? - How to set user_id on Entity update? 从春季项目到非春季项目的会话“ user_id” - Session “user_id” from spring project to non-spring project MySQL 从两个不同的表中获取用户 ID 和密码的查询 - MySQL a query to get user_id and password from two different tables 如何将“/ user / {user_id}”之类的网址映射到特定操作? - How to map URL like “/user/{user_id}” to a specific action? 应用程序未使用 user_id,并且表在用户表中也没有 user_id,但出现错误,因为列名 user_id 无效 - application is not using user_id and table also doesnt have user_id in users table, but getting error as The column name user_id is not valid MySQL-每个日期每个user_id的SELECT MIN时间 - MySQL - SELECT MIN time per user_id per date 如何从请求 header 中获取 user_id 而不是将其作为请求参数传递? 然后通过header发回 - How can I get the user_id from the request header instead of passing it as a request parameter? And then send it back through the header 休眠字段“ user_id”没有默认值 - hibernate Field 'user_id' doesn't have a default value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM