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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:48:52+00:00 2026-06-05T01:48:52+00:00

I have a simple code that manages to successfully query an SQLite Database and

  • 0

I have a simple code that manages to successfully query an SQLite Database and convert that result from cursor to string in order to display it on screen.

My problem now would be invalid queries that make the App Crash. Would there be a way to successfully handle invalid queries? Preferably something that would keep my app from crashing and would just redirect the user to the home page and display a toast of warning.

So far my method for searching looks like this:

public String search(DataBaseHelper myDB){
    SQLiteDatabase db = myDB.getReadableDatabase();
    Cursor cursor = db.rawQuery("SELECT BuildingColor, Room FROM LSBuildingsDB WHERE _id =" + newString, null);

    cursor.moveToFirst();

    String data = cursor.getString(cursor.getColumnIndexOrThrow("BuildingColor")) + " " +
                    cursor.getString(cursor.getColumnIndex("Room"));

    //Toast msg = Toast.makeText(getBaseContext(),data, Toast.LENGTH_SHORT);
    //msg.show();

    cursor.close();

    return data;

}
  • 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-05T01:48:54+00:00Added an answer on June 5, 2026 at 1:48 am
    Cursor cursor = NULL ;
    try
    {
       cursor = db.rawQuery("SELECT BuildingColor, Room FROM LSBuildingsDB WHERE _id =" + newString, null);
       if(cursor != NULL)
       {
          try {
             if (cursor.moveToNext()) {
                String data = cursor.getString(cursor.getColumnIndexOrThrow("BuildingColor")) + 
                   " " + cursor.getString(cursor.getColumnIndex("Room"));
             } else {
                // Query result was empty, deal with it here.
             }
          } finally {
            // Cursors should be closed
            cursor.close();
          }
       }
    }
    catch (SQLiteException e) // (Exception e) catch-all:s are bad mmkay.
    {
        //print exception
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple piece of code that extracts a float from a FORTRAN-generated
I have done a simple code for a slideshow that dynamicly loads images from
I have simple html code that plays YouTube video after click on the image:
I have this simple code that plans to Scan a QR Code and return
I have this simple code that speaks for itself. <script language='javascript"> function check() {}
Basically I have some simple code that does some things for files and I'm
I have a simple jQuery code that runs on a web page that has
I have a simple little code fragment that is frustrating me: HashSet<long> groupUIDs =
I have a very simple bit of code that is supposed to capture the
I have a simple assembly code file called exit.s that looks like the following:

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.