SQLITE数据库中没有此类列错误

时间:2017-04-03 08:54:43

标签: android sqlite android-sqlite

我在logcat中收到错误,因为它没有任何列,并且插入正确          我怎样才能解决这个问题。由我给出的值正确表示,但SELECT查询不适用于数据库表中的值。

    String search = "select * from "+ TABLE_NAME +" Where PHONENO =" +num+ "                                         
           and NAME = "+name1+" and LASTNAME =" +lastname1;
           Cursor c = db.rawQuery(search,null);
           boolean res = c.moveToFirst();
         if (res) {
        String s1  = c.getString(0);
        String s2 = c.getString(1);
        String s3  = c.getString(2);
        String s4  = c.getString(3);
        String s5  = c.getString(4);
        String s6  = c.getString(5);
        String s7  = c.getString(6);
        String s8  = c.getString(7);
        String s9  = c.getString(8);
        String s10  = c.getString(9);
        String s11  = c.getString(10);
        String s12  = c.getString(11);
        String s13  = c.getString(12);
        String s14  = c.getString(13);
        String s15  = c.getString(14);
        String array[] ={s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15};
        Intent i  = new Intent(this,SelectMember.class);
        i.putExtra("k1",array);
        startActivity(i);
    }

logcat的

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.user.database, PID: 9112
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5198) 
at android.view.View$PerformClick.run(View.java:21147) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.database.sqlite.SQLiteException: no such column: durga (code 1): , while compiling: select * from MASTER_ACCOUNTS Where PHONENO =8121680624 and NAME = durga and LASTNAME =veerepalli                      at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
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:1316)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1255)
at com.example.user.database.Editoption.search(Editoption.java:36)
at java.lang.reflect.Method.invoke(Native Method) 
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) 
at android.view.View.performClick(View.java:5198) 
at android.view.View$PerformClick.run(View.java:21147) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Application terminated.

2 个答案:

答案 0 :(得分:0)

字符串文字应放在单引号('

Where PHONENO ='" +num+ "' and NAME = '"+name1+"' and LASTNAME ='" +lastname1 +"'";

答案 1 :(得分:0)

  

引起:android.database.sqlite.SQLiteException:没有这样的列:   durga(代码1):,编译时:select * from MASTER_ACCOUNTS Where   PHONENO = 8121680624,NAME = durga和LASTNAME = veerepalli

首先纠正您的查询。

告知您 NO such table

"SELECT * FROM "+ TABLE_NAME +" WHERE PHONENO ='" +num+ "' AND NAME = '"+ name1 +"' AND LASTNAME ='" + lastname1 +"'";

然后卸载旧应用清理 - 重建 - 运行