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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:42:32+00:00 2026-05-23T13:42:32+00:00

I have been learning (slowly but surely) how to do deal with sqlite databases

  • 0

I have been learning (slowly but surely) how to do deal with sqlite databases on android systems. Using information I found here:

http://mfarhan133.wordpress.com/2010/10/24/database-crud-tutorial-for-android/

I have learned how to create, load things into and retrieve information from a database on my android system. One of the hitches was this method here:

 public Cursor getClientsCursor() {
        StudioTabOpenHelper dbAdapter=StudioTabOpenHelper.getDBAdapterInstance(this.getListView().getContext());
        try {

            dbAdapter.createDatabase();
        } catch (IOException e) {
            Log.i("*** select ",e.getMessage());
        }
        dbAdapter.openDataBase();       
        String query="SELECT * FROM CLIENTS;";
        Cursor c = dbAdapter.selectRecordsFromDB(query, null);
        //dbAdapter.close();
        return c;
    }

The problem was that the above code was closing the adapter I had opened…this was causing the part where I used that returned cursor to complain that database conn#0 already closed. So I commented out that dbAdapter.close(); I think this is bad in the future if i call this method again.

So my question is: Should I at the start of my application create the dbAdapter and open the database and leave it open and never close it? (how do i pass the dbAdapter around to activities, fragments etc if I go this route) … or how can I use the getClientsCursor method as is and figure out some other way to pass back the cursor and be able to call the .close()?

 /**
 * Open the database
 * @throws SQLException
 */
public void openDataBase() throws SQLException {
    String myPath = DB_PATH + DATABASE_NAME;
    myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
}


  /**
 * Close the database if exist
 */
@Override
public synchronized void close() {
    if (myDataBase != null)
        myDataBase.close();
    super.close();
}

My adapter code was gotten from here:

http://mfarhan133.wordpress.com/2010/10/24/database-crud-tutorial-for-android/

I just didn’t call my class DBAdapter but called it StudioTabOpenHelper.

  • 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-23T13:42:32+00:00Added an answer on May 23, 2026 at 1:42 pm

    You may close your adapter on the
    onDestroy() method of your activity.

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

Sidebar

Related Questions

I have been slowly learning SQL the last few weeks. I've picked up all
I have been learning about the basics of C# but haven't come across a
I have been slowly learning iPhone development and seem to keep hitting walls where
I have been learning prolog.. I'm using a editor named prol1.1.1 I need to
I have been using Grails for last 3 weeks (learning and working). I have
I have been using Silverlight for quite a bit and am learning Windows Phone
I still learning Ruby on Rails, but have been wondering what happens if I
I have been using the Learning Java 2nd Edtion book to try make my
I am continually studying up on languages I have been using and learning, as
I am currently learning MVVM abd the tutorial I have been using, simply uses

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.