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 8184037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:21:49+00:00 2026-06-07T01:21:49+00:00

I have a problem with last_insert_rowid(). In my DB-Helper-Class I am doing the following:

  • 0

I have a problem with “last_insert_rowid()”.

In my DB-Helper-Class I am doing the following:

public int getLastID() {
    final String MY_QUERY = "SELECT last_insert_rowid() FROM "+ DATABASE_TABLE5;
    Cursor cur = mDb.rawQuery(MY_QUERY, null);
    cur.moveToFirst();
    int ID = cur.getInt(0);
    cur.close();
    return ID;
}

But when I call this in my intent:

int ID = mDbHelper.getLastID(); 
Toast.makeText(this, "LastID: " + ID, Toast.LENGTH_SHORT).show();

I get always “0” back. That can not be, cause I have a lot of entries in my DB and the autoincrement value should be much higher.

What I am doing wrong?

  • 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-07T01:21:51+00:00Added an answer on June 7, 2026 at 1:21 am

    OK, that was the right hint John 😉

    The query should look like this:

    public int getHighestID() {
    final String MY_QUERY = "SELECT MAX(_id) FROM " + DATABASE_TABLE5;
    Cursor cur = mDb.rawQuery(MY_QUERY, null);
    cur.moveToFirst();
    int ID = cur.getInt(0);
    cur.close();
    return ID;
    }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem building a HTML table from the following JSON [ {
I have problem with UIWebView delay when the load image from url. In my
I'm using MySQL and have the following entity: class MyEntity { @Id @GeneratedValue(strategy=IDENTITY) @Column(name=id)
I seem to have problem getting affected_rows when I INSERT and SELECT, it just
I have a problem inserting string elements in a string array... For example, I
I have a problem with starting the sunspot server. last week it worked like
I have the same problem as described in ( Last record of Join table
I have an interesting problem here I've been trying to solve for the last
I have an interesting problem. The basis of the problem is that my last
I have encountered a weird problem, when i built my last ad-hoc version for

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.