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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:57:22+00:00 2026-05-26T04:57:22+00:00

I created a static method to access my database on one of my activities

  • 0

I created a static method to access my database on one of my activities but I keep getting error on opening the database.

MainActivity

 public static String getStudentData() {

    SQLiteDatabase sampleDB =  null;

    try {
            //NOT WORKING
        sampleDB =  SQLiteDatabase.openDatabase("studentDB",null, SQLiteDatabase.CREATE_IF_NECESSARY); 
            //Also not working
        //sampleDB =  SQLiteDatabase.openOrCreateDatabase("studentDB", null);

        Cursor c = sampleDB.rawQuery("SELECT * FROM student where id='1'", null);

        if (c != null ) {
            if  (c.moveToFirst()) {
                do {
                    //...                       
                }while (c.moveToNext());
            } 
        }
        c.close();
    } catch (Exception se ) {
    } finally {
            sampleDB.close();
    }
}

OtherActivity

String student = MainActivity.getStudentData();

I have been getting sqlite3_open_v2("studentDB", &handle, 6, NULL) failed. Cant find what’s wrong… I have also tried using MODE_WORLD_WRITEABLE. Currently using MODE_PRIVATEfor database creation. Please help me out!

  • 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-26T04:57:22+00:00Added an answer on May 26, 2026 at 4:57 am

    First argument to openDatabase should be full path to db so if:

    //The Android's default system path of your application database.
    private static String DB_PATH = "/data/data/YOUR_PACKAGE/databases/";
    
    private static String DB_NAME = "studentDB";
    

    then you should call:

    sampleDB =  SQLiteDatabase.openDatabase(DB_PATH + DB_NAME, null, SQLiteDatabase.CREATE_IF_NECESSARY); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I call a static method like: Something.action(); Since a instance isn't created how
Is it possible to create a generic method with a signature like public static
I have created a static library following this link . But I am facing
Is a string literal in C++ created in static memory and destroyed only when
I have created a public static class utils.cs I want to use it in
I created a Java code that tries to access the method LoadProject of the
I'm having trouble querying my SQLite database using Android. I keep getting either an
Have a small doubt with static method. Documentation says that Static method can't access
In Java static methods are created to access it without any object instance. It
How do I access the method myMethod from another class? public class controller extends

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.