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

  • Home
  • SEARCH
  • 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 6214571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:54:06+00:00 2026-05-24T06:54:06+00:00

Using the typical SQLiteDatabase object in Android’s API, what can I do to get

  • 0

Using the typical SQLiteDatabase object in Android’s API, what can I do to get the next AUTO_INCREMENT value of a particular column (ie. id) without affecting the value itself. Is there a method for that? Or what query should I execute to get that result. Keep in mind that SQLiteDatabase.query() returns a Cursor object, so I’m not too sure how to deal with that directly if I just want to get a value out of it.

  • 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-05-24T06:54:06+00:00Added an answer on May 24, 2026 at 6:54 am

    You’re right. The first answer (still below) only works without an AUTOINCREMENT for id. With AUTOINCREMENT, the values are stored in a separate table and used for the increment. Here’s an example of finding the value:

    public void printAutoIncrements(){
        String query = "SELECT * FROM SQLITE_SEQUENCE";
        Cursor cursor = mDb.rawQuery(query, null);
        if (cursor.moveToFirst()){
            do{
                System.out.println("tableName: " +cursor.getString(cursor.getColumnIndex("name")));
                System.out.println("autoInc: " + cursor.getString(cursor.getColumnIndex("seq")));
    
            }while (cursor.moveToNext());
        }
    
        cursor.close(); 
    
    }
    

    See: http://www.sqlite.org/autoinc.html

    First Answer:

    You can query for the max of the _id column, such as:

    String query = "SELECT MAX(id) AS max_id FROM mytable";
    Cursor cursor = db.rawQuery(query, null);
    
    int id = 0;     
    if (cursor.moveToFirst())
    {
        do
        {           
            id = cursor.getInt(0);                  
        } while(cursor.moveToNext());           
    }
    return id;
    

    This works for row ids that haven’t been specified as “INTEGER PRIMARY KEY AUTOINCREMENT” (all tables have a row id column).

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

Sidebar

Related Questions

On a typical OS how many files can i have opened at once using
Consider this typical disconnected scenario: load a Customer object from SQL Server using LINQ
I'm using JSONP to get data from a server. The more typical method of
I've got a typical webform that submits using the ajax module. How can I
Can a typical Lisp dialect solve problems using the bottom-up dynamic programming approach? (Please
Im using a typical situation with UINavigationController, id like to make the navigation bar
I am able to send emails using the typical C# SMTP code across Exchange
I would select multiple DOM elements using a typical code such as this: $('#ele1,
I have an NSTableView that is done using the typical IB and data bindings.
What is a typical approach to using the repository pattern with .NET 1.1 (C#)?

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.