0

While running my application using Sqlite i am getting the below error.

SQLiteLog(779): (1) near "SQXC31DLT": syntax error
System.out(779): DATABASE ERROR android.database.sqlite.SQLiteException: near "SQXC31DLT": syntax error (code 1): , while compiling: SELECT  count(*) FROM MessageTable  WHERE userID =? SQXC31DLT

Code:

Here is my query

   String query = "INSERT INTO MessageTable (user_message_id,message,title,message_time,mp3,userID) values ('" + 

              umsermessgid + "','" + Messages +"','" + Title +"','" + timedate+ "','" + musicmp3 + "','" + userid + "')";


                     sqlHandler.executeQuery(query);
                        showList();

Here is the remaining showlist() method:

 private void showList() {
            // TODO Auto-generated method stub
            contactList = new ArrayList<ContactListItems>();
             contactList.clear();
             userid=    mDataStorage.getToken(FirstActivity.this);

String query = "SELECT  count(*) FROM MessageTable  WHERE userID = '" + userid +"'";              Cursor c1 = sqlHandler.selectQuery(query);
              if (c1 != null && c1.getCount() != 0) {
               if (c1.moveToFirst()) {
              //  do {
                 ContactListItems contactListItems = new ContactListItems();

                 contactListItems.setSlno(c1.getString(c1.getColumnIndex("ID")));
                 contactListItems.setmessage(c1.getString(c1.getColumnIndex("message")));
                 contactListItems.settitle(c1.getString(c1.getColumnIndex("title")));
                 contactListItems.setmp3(c1.getString(c1.getColumnIndex("mp3")));
                 contactListItems.setusermessageid(c1.getString(c1.getColumnIndex("user_message_id")));
                 contactList.add(contactListItems);

               // } while (c1.moveToNext());
               }
              }
              c1.close();


        }

I have checked everything but still i am receiving error

CursorWindow(1211): Failed to read row 0, column -1 from a CursorWindow which has 1 rows, 1 columns.



   05-18 10:37:11.022: E/AndroidRuntime(1211): FATAL EXCEPTION: main
05-18 10:37:11.022: E/AndroidRuntime(1211): java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
05-18 10:37:11.022: E/AndroidRuntime(1211):     at android.database.CursorWindow.nativeGetString(Native Method)
05-18 10:37:11.022: E/AndroidRuntime(1211):     at android.database.CursorWindow.getString(CursorWindow.java:434)
05-18 10:37:11.022: E/AndroidRuntime(1211):     at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
05-18 10:37:11.022: E/AndroidRuntime(1211):     at com.example.universal.FirstActivity.showList(FirstActivity.java:330)
05-18 10:37:11.022: E/AndroidRuntime(1211):     at com.example.universal.FirstActivity.access$1(FirstActivity.java:317)
05-18 10:37:11.022: E/AndroidRuntime(1211):     at com.example.universal.FirstActivity$GetTask.onPostExecute(FirstActivity.java:137)
05-18 10:37:11.022: E/AndroidRuntime(1211):     at com.example.universal.FirstActivity$GetTask.onPostExecute(FirstActivity.java:1)
05-18 10:37:11.022: E/AndroidRuntime(1211):     at android.os.AsyncTask.finish(AsyncTask.java:631)
05-18 10:37:11.022: E/AndroidRuntime(1211):     at android.os.AsyncTask.access$600(AsyncTask.java:177)
05-18 10:37:11.022: E/AndroidRuntime(1211):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
05-18 10:37:11.022: E/AndroidRuntime(1211):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-18 10:37:11.022: E/AndroidRuntime(1211):     at android.os.Looper.loop(Looper.java:137)
05-18 10:37:11.022: E/AndroidRuntime(1211):     at android.app.ActivityThread.main(ActivityThread.java:5041)
05-18 10:37:11.022: E/AndroidRuntime(1211):     at java.lang.reflect.Method.invokeNative(Native Method)
05-18 10:37:11.022: E/AndroidRuntime(1211):     at java.lang.reflect.Method.invoke(Method.java:511)
05-18 10:37:11.022: E/AndroidRuntime(1211):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-18 10:37:11.022: E/AndroidRuntime(1211):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-18 10:37:11.022: E/AndroidRuntime(1211):     at dalvik.system.NativeStart.main(Native Method)

Can anybody help me to solve this issue!! @Thanks

4

3 回答 3

1

你的查询是错误的。

利用:

String query = "SELECT  count(*) FROM MessageTable  WHERE userID =" + userid ;

在你的 showList() 函数中。

于 2013-05-18T10:28:40.803 回答
0

你想用你的代码做什么?

此 sql 查询应该是您的第一个问题的正确查询:

String query = "SELECT count(*) FROM MessageTable WHERE userID = '" + userid +"'"; (古纳西兰)

这个错误:

无法从具有 1 行 1 列的 CursorWindow 读取第 0 行第 -1 列。

是因为您使用了错误的查询。您正在使用的查询仅返回一个数字 - 计数。(一列一行)

此代码的正确查询:

光标 c1 = sqlHandler.selectQuery(query); if (c1 != null && c1.getCount() != 0) { if (c1.moveToFirst()) { // do { ContactListItems contactListItems = new ContactListItems();

             contactListItems.setSlno(c1.getString(c1.getColumnIndex("ID")));
             contactListItems.setmessage(c1.getString(c1.getColumnIndex("message")));
             contactListItems.settitle(c1.getString(c1.getColumnIndex("title")));
             contactListItems.setmp3(c1.getString(c1.getColumnIndex("mp3")));
             contactListItems.setusermessageid(c1.getString(c1.getColumnIndex("user_message_id")));
             contactList.add(contactListItems);

           // } while (c1.moveToNext());
           }
          }
          c1.close();

应该:

字符串查询 = "SELECT * FROM MessageTable WHERE userID = '" + userid +"'";

并不是:

String query = "SELECT count(*) FROM MessageTable WHERE userID = '" + userid +"'";

于 2013-05-18T11:53:11.290 回答
0

更改您的查询,如下所示

String query = "SELECT  count(*) FROM MessageTable  WHERE userID = '" + userid +"'";

或尝试如下。

Cursor c = db.rawQuery("SELECT count(*) FROM MessageTable where userID = '"+ userid + "'", null);
于 2013-05-18T10:35:44.740 回答