SQLite的rawQuery错误 [英] SQLite rawQuery error

查看:216
本文介绍了SQLite的rawQuery错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是prerry新的SQLite。我有一个用户的详细信息,SQLite数据库这样

I'm prerry new to SQLite. I have a SQLite database with a user's details like this

public static final String USER_ID = "email";
public static final String USER_NAME = "user_name";
public static final String PASSWORD = "password";

public static final String DATABASE_NAME = "molo.db";
public static final String DATABASE_TABLE = "user_profile";
private static final int DATABASE_VERSION = 1;

//SQL to create new database
private static final String DATABASE_CREATE = 
        "create table " + DATABASE_TABLE +
        " (" +
        USER_ID + " TEXT PRIMARY KEY NOT NULL UNIQUE , " +
        USER_NAME + " TEXT NOT NULL, " +
        PASSWORD + " TEXT NOT NULL);"; 

我可以注册新用户,它工作正常,我可以看到,它的工作原理,当我拉数据库从仿真器。 我现在正在努力与被媒体链接存储在数据库中用户的详细信息登录。我已经搜查,发现了几个解决方案,这一点,但是当我尝试执行它我收到错误。我想这样的:

I can register new users and it works fine, I can see that it works when I pull the database from the emulator. I am now trying to log in with a user's details that is allready on stored on the database. I have searched and found a couple of solutions to this, however when I try to implement it I am receiving errors. I tried this:

public boolean verification(String Email) throws SQLException
{
    Cursor c = database.rawQuery("SELECT * FROM "+ user_pofile +" WHERE "+ email + "=" + Email, null);
    if (c!=null)
    {
        return true;
    }
    return false; 
}

,以确定该用户的电子邮件媒体链接在数据库内是否存在。任何人都可以解释为什么 USER_PROFILE 电子邮件时,他们是正确的表和列名突出显示为错误在上面rawQuery ?我失去了进口或东西吗? 干杯

to determine if the user's email allready exists within the database. Can anyone explain why user_profile and email are highlighted as error in the above rawQuery when they are the correct table and column names? Am I missing imports or something? Cheers

推荐答案

user_pofile (错字有)和电子邮件没有双引号括起来,使他们被视为Java变量名和你没有在code。通过这样的名称变量。

user_pofile (typo there) and email are not in double quotes so they are treated as Java variable names and you don't have variables by such name in your code.

如果你想使用的变量,替换 DATABASE_TABLE USER_ID 或只是把 USER_PROFILE 电子邮件中的双引号。

If you want to use variables, replace with DATABASE_TABLE and USER_ID or just put the user_profile and email in the double quotes.

此外,你需要在单引号引用您的SQL字符串或使用变量。

Additionally, you need to quote string literals in your SQL in single quotes, or use variables.

例如,

rawQuery("SELECT * FROM user_profile WHERE email = ? ", new String[] { Email })

此外,光标将不能为空,并检查将没有真正的工作。要查看查询是否匹配的话,请检查 moveToFirst()返回

Moreover, Cursor won't be null and checking for null won't really work. To see whether the query matched anything, check that moveToFirst() returns true.

这篇关于SQLite的rawQuery错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆