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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:28:05+00:00 2026-06-15T14:28:05+00:00

sir, how can i return the rowid of my database depending on the inputs

  • 0

sir, how can i return the rowid of my database depending on the inputs name, number? this code just return the value 0 everytime. my primary key is KEY_ROWID. thanks for help in advance

//get rowid
public long getRowId(String name, String number) 
{
    // TODO Auto-generated method stub
    String[] columns = new String[]{KEY_ROWID, KEY_NAME, KEY_NUMBER};
    Cursor c = ourDatabase.query(DATABASE_TABLE, columns, KEY_NUMBER+ "=" +number, null, null, null, null);

    long rowid = c.getColumnIndex(KEY_ROWID);
    return rowid;
}

here is how i access it

public void onClick(View arg0) {
            nameChanged = sqlName.getText().toString();
            numChanged = sqlNumber.getText().toString();
            GroupDb info = new GroupDb(EditDetails.this);
            info.open();
            long rowid = info.getRowId(name, num);
            info.updateNameNumber(rowid, nameChanged, numChanged);
            Toast.makeText(getApplicationContext(), rowid+" "+nameChanged+" "+numChanged, Toast.LENGTH_LONG).show();
            ArrayList<Contact> searchResults = info.getView();
            MyCustomBaseAdapter mcba = new MyCustomBaseAdapter(EditDetails.this, searchResults);
            mcba.updateResults(searchResults);
            Toast.makeText(getApplicationContext(), "Update Successful!", Toast.LENGTH_LONG).show();
            info.close();
            }
        });
  • 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-15T14:28:06+00:00Added an answer on June 15, 2026 at 2:28 pm

    From the fine manual:

    public Cursor query (String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit)
    […]
    Returns

    A Cursor object, which is positioned before the first entry.

    So first you have step c into the result set and you can use moveToFirst for that:

    c.moveToFirst();
    

    Now you need to extract the rowid from the row that the cursor is pointing at. But getColumnIndex is for mapping a column name to a position in the row:

    Returns the zero-based index for the given column name, or -1 if the column doesn’t exist.

    You’re getting a zero from getColumnIndex because your KEY_ROWID is the first column in your SELECT query.

    I think you’re looking for getLong if you want to extract a long from the Cursor‘s result set:

    long rowid = c.getLong(c.getColumnIndex(KEY_ROWID));
    

    If you know the structure of your query (which you do), you could skip the getColumnIndex call and just use the known index:

    long rowid = c.getLong(0);
    

    And if all you’re doing is looking up the rowid, you can SELECT just KEY_ROWID:

    String[] columns = new String[]{KEY_ROWID};
    

    There’s no need to pull things out of the database that you’re ignoring.

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

Sidebar

Related Questions

just a simple question here. How can I get the return value on this
Edited........ sorry Sir I was referring this piece of code from Stephen Toub's article..
I have the following code from apache's svn. As you can see this is
Sir, I am having some problem regarding database in SQL Server. My project is
sir i have working with db connectivity i have written all code and i
sir, can you help me on how i can display the details from a
sir, how can i refresh my custom listview using baseadapter. i don't know what
Need help with this error. Can't see what's wrong. Error: Warning: mysql_query() expects parameter
Dear Sir/m'am How can i replace ther deprecated ereg_replace with preg_replace or str_replace and
how can i add collision effects on my sprites... sir i'm using sprite 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.