Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 检查列是否存在_Java_Android_Sqlite - Fatal编程技术网

Java 检查列是否存在

Java 检查列是否存在,java,android,sqlite,Java,Android,Sqlite,当我尝试检查该列是否存在时,它会使用以下错误压碎应用程序: Caused by: android.database.sqlite.SQLiteException: no such column: perfumes (code 1): , while compiling: SELECT * FROM savedproducts WHERE pid = 1 AND ptype = perfumes at android.database.sqlite.SQLiteConnection.nativeP

当我尝试检查该列是否存在时,它会使用以下错误压碎应用程序:

Caused by: android.database.sqlite.SQLiteException: no such column: perfumes (code 1): , while compiling: SELECT * FROM savedproducts WHERE pid = 1 AND ptype = perfumes
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1113)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:690)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1438)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1377)
at app.botikaty.com.DatabaseHandler.CheckIfExist(DatabaseHandler.java:137)
at app.botikaty.com.ViewProductActivity.onCreate(ViewProductActivity.java:80)
java:80

int issaved = dbHandler.CheckIfExist(theproductid,theproducttype);
            if (issaved != -1){
                savebtn.setLiked(true);
            }else{
                savebtn.setLiked(false);
            }
我希望问题清楚易懂,请问怎么办

我使用过的一些文件:

DatabaseHandler.java->


Contact.java->

您需要将其更改为:

 String countQuery = "SELECT * FROM " + TABLE_CONTACTS + " WHERE pid = " + id + " AND ptype = '" + type+"'";
这只是在类型字符串周围加上单引号,表示它是数据库的字符串值

因此,查询将如下所示: 从保存的产品中选择*,其中pid=1,ptype='香水'

不同之处在于实际查询中的ptype=香水与ptype=香水

您没有在类型字符串周围加单引号,因此数据库认为您试图获取一个列,而实际上您试图告诉它ptype的值

 String countQuery = "SELECT * FROM " + TABLE_CONTACTS + " WHERE pid = " + id + " AND ptype = '" + type+"'";