Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8701291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:21:44+00:00 2026-06-13T02:21:44+00:00

I have a db that is structred as such uid | username | password

  • 0

I have a db that is structred as such

uid | username | password |     email   | cur_level
1     default      abc123   me@email.com    0

In my game after you complete a level in the main activity I run a method called increase_current_level()
value++;
test_db.open();
test_db.updateLevel(value);
cur_level = value;
test_db.close();

So that seems to work with no problems but when test_db.updateLevel(value) is run, that when the program crashes.

In my DBHelper the code for update level is as follows.

public boolean updateLevel(String level) {
        ContentValues args = new ContentValues();

        args.put(KEY_CUR_LEVEL, level);
        return mDb.update(DATABASE_TABLE, args, KEY_ROWID + "="
                + "WHERE id=(SELECT max(id) FROM DATABASE_TABLE)", null) > 0;

    }

My log cat error seems to be:

10-17 17:36:10.833: E/AndroidRuntime(1815): Caused by: android.database.sqlite.SQLiteException: near "WHERE": syntax error (code 1): , while compiling: UPDATE test SET cur_level=? WHERE _id=WHERE id=(SELECT max(id) FROM DATABASE_TABLE)

I’m very new to SQLite so, it’s kind of intimidating, but I hope someone sees a very obvious flaw. Thanks

Update 1:

My updated code:

public boolean updateLevel(String level) {
    ContentValues args = new ContentValues();

    args.put(KEY_CUR_LEVEL, level);
    return mDb.update(DATABASE_TABLE, args, KEY_ROWID + " = (SELECT max(id) FROM DATABASE_TABLE",
            null) > 0;

}

Updated error msg:

10-17 18:26:50.804: E/AndroidRuntime(3684): Caused by: android.database.sqlite.SQLiteException: near "DATABASE_TABLE": syntax error (code 1): , while compiling: UPDATE test SET cur_level=? WHERE _id = (SELECT max(id) FROM DATABASE_TABLE
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:21:45+00:00Added an answer on June 13, 2026 at 2:21 am

    The syntax of mDb.update is

    update(table, ContentValues values, String whereClause, String[] whereArgs)
    

    Let’s assume that KEY_ROWID = "id"

    For your whereClause, you’re literally passing

    "id = WHERE id = (SELECT max(id) FROM DATABASE_TABLE"
    

    which is not valid SQL.

    You don’t seem to need “id =“. Just start your WHERE clause with “WHERE id=“

    However, your question implies that you have only one record in the DB. Why use a DB for one record? And if you have more than one record in it, you should use a WHERE clause that searches on something unique, rather than using SELECT max(id).

    The bottom line is that you need to improve your knowledge of SQL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have code that maintains a parent/children structure. In such a structure I
I have a table with such structure: uid sid all integers. This table simulates
I have an array that is structured as such: $data = array( abc=>array( label
So I have an SQL Table structure such that I have Blogs which have
I have some XML that is structured like this: <whatson> <productions> <production> <category>Film</category> </production>
I have a linux utility that parses structured input ( a text file ),
I have a set of data that is structured like this: ItemA.GroupA ItemB.GroupA ItemC.GroupB
I have a collection of HTML elements that is structured and hierarchical. When an
I have a simple html form that is structured something like this: <form name=test
I have a highly structured hierarchical directory containing multiple files that need to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.