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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:48:41+00:00 2026-06-11T08:48:41+00:00

I have a SQLite table of this tipe Table Vehicles : CATEGORY COUNTRY ID

  • 0

I have a SQLite table of this tipe

Table Vehicles:

CATEGORY    COUNTRY   ID    NAME          EMAIL
A           GE         1    BMW           sample1@salple.it
A           GE         2    Lamborghini   sample2@salple.it
B           GE         3    BMW           sample3@salple.it

I want to select all the entries that have a specified name or a specified category and pass all the parameters how each row in a constructor

Vehicle(String category, String country, int id, String name, String email)

I have implemented this adapter using some tutorials:

public class TestAdapter  
{ 
    protected static final String TAG = "DataAdapter"; 

    private final Context mContext; 
    private SQLiteDatabase mDb; 
    private DataBaseHelper mDbHelper; 

    public TestAdapter(Context context)  
    { 
        this.mContext = context; 
        mDbHelper = new DataBaseHelper(mContext); 
    } 

    public TestAdapter createDatabase() throws SQLException  
    { 
        try  
        { 
            mDbHelper.createDataBase(); 
        }  
        catch (IOException mIOException)  
        { 
            Log.e(TAG, mIOException.toString() + "  UnableToCreateDatabase"); 
            throw new Error("UnableToCreateDatabase"); 
        } 
        return this; 
    } 

    public TestAdapter open() throws SQLException  
    { 
        try  
        { 
            mDbHelper.openDataBase(); 
            mDbHelper.close(); 
            mDb = mDbHelper.getReadableDatabase(); 
        }  
        catch (SQLException mSQLException)  
        { 
            Log.e(TAG, "open >>"+ mSQLException.toString()); 
            throw mSQLException; 
        } 
        return this; 
    } 

    public void close()  
    { 
        mDbHelper.close(); 
    } 



    public boolean SaveVehicles(String category , String country, String id, String name, String email) 
    {
        try
        {
            ContentValues cv = new ContentValues();
            cv.put("Category", category);
            cv.put("Country", country);
            cv.put("id", id);
            cv.put("Name", name);
            cv.put("Email", email);

            mDb.insert("Vehicles", null, cv);

            Log.d("SaveVehicles", "informationsaved");
            return true;

        }
        catch(Exception ex)
        {
            Log.d("SaveVehicles", ex.toString());
            return false;
        }
    }


} 

But I don’t know how I could implement the various get methods that I need, to meet a solution to my problem.

  • 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-11T08:48:42+00:00Added an answer on June 11, 2026 at 8:48 am

    Creating an object from a SQL query would look something like this

    /**
     * @return Returns a list of all objects.
     */
    public ArrayList<Object> getAllObjects() 
    {
        // Select All Query
        String selectQuery = "SELECT * FROM SOME_TABLE";
        // Get the isntance of the database
        SQLiteDatabase db = this.getWritableDatabase();
        //get the cursor you're going to use
        Cursor cursor = db.rawQuery(selectQuery, null);
    
        //this is optional - if you want to return one object
        //you don't need a list
        ArrayList<Object> objectList = new ArrayList<Object>();
    
        //you should always use the try catch statement incase
        //something goes wrong when trying to read the data
        try
        {           
            // looping through all rows and adding to list
            if (cursor.moveToFirst()) {
                do {
                     //the .getString(int x) method of the cursor returns the column
                     //of the table your query returned
                    Object object= new Object(Integer.parseInt(cursor.getString(0)),
                                            Integer.parseInt(cursor.getString(1)),
                                            Integer.parseInt(cursor.getString(2)),
                                            cursor.getString(3),
                                            cursor.getString(4),
                                            cursor.getString(5),
                                            Boolean.parseBoolean(cursor.getString(6))
                                            );                                      
                    // Adding contact to list
                    objectList.add(object);
                } while (cursor.moveToNext());
            }
        }
        catch (SQLiteException e)
        {
            Log.d("SQL Error", e.getMessage());
            return null;
        }
        finally
        {
          //release all your resources
            cursor.close();
            db.close();
        }
        return objectList;      
    }
    

    The code above assumes you have some table in your database named “SOME_TABLE” and that you have an object that takes 7 parameters but you should be able to alter the snippet to make it work for you.

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

Sidebar

Related Questions

I have a SQLite database with this format: TABLE users | |---------name - text
In this example we have 3 related tables on a SQLite database: CREATE TABLE
I need to achieve this: I have a sqlite table with this data slno
I have an sqlite database on android created like this: sqlite> .schema CREATE TABLE
i have this sqlite table: CREATE TABLE frames (videomd5 TEXT, framemd5 TEXT, type TEXT,
I have SQLite table with columns id and name. I return array of those
I have a SQLite table called Price like this: date, productId, price ---------------------- 20120601,
I have an sqlite table log that looks like this: ID p_id viewer ----------------------
i have an sqlite table with 2000 records. I need to show this records
I have this table in my Android SQLite DB: CREATE TABLE statistics (subject TEXT,

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.