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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:42:11+00:00 2026-06-11T11:42:11+00:00

I’m using multiple SQLite databases in my android java project. The first one (for

  • 0

I’m using multiple SQLite databases in my android java project. The first one (for a login) works fine, using the following code and I am closing the connection. However, on the following page i’m calling a function which uses a different database but it seems to still reference the first database and not the new one. I’m getting this error:

09-14 13:18:01.990: I/SqliteDatabaseCpp(10035): sqlite returned: error code = 1, msg = no such table:
 NextID, db=/mnt/extSdCard/DirectEnquiries/AuditingData/Static/Users

Which is right, NextID isn’t in Users.

Here is the code for the login page which uses the Users table:

if(String.valueOf(loginCount).equals("2")) {

        File dbfile = new File(Global.StaticDB + "/Users" ); 
        SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbfile, null);

        Cursor c = db.rawQuery("SELECT UserID from Users where UserID like '" + txtUsername.getText().toString().trim() + "' AND Password like '" + txtPassword.getText().toString().trim() + "'", null); 
        c.moveToFirst();

        if(c.getCount() > 0) {
            Global.Username = c.getString(c.getColumnIndex("UserID"));
            Global.currentDB = spnLocation.getSelectedItem().toString();
            Global.currentDBfull = Global.sctArea + Global.currentDB;

            db.close();
            Context context = getApplicationContext();
            CharSequence text = "Logged In";
            int duration = Toast.LENGTH_SHORT;
            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
            Intent ShowMainPage = new Intent(view.getContext(), MainPage.class);
            startActivityForResult(ShowMainPage, 0);


        }

The next page is using this:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_page);
    TextView txt = (TextView) findViewById(R.id.textView1);
    txt.setText(Global.Username);
    TextView dbtxt = (TextView) findViewById(R.id.txtDB);
    dbtxt.setText(Functions.getNextID("StationObjects"));

}

And the function is:

public static int getNextID(String tablename) {
    Log.e("Current DB is: ", Global.currentDBfull);
    File dbfile = new File(Global.currentDBfull); 
    SQLiteDatabase dbF = SQLiteDatabase.openOrCreateDatabase(dbfile, null);

    int rtnID=(int)DatabaseUtils.longForQuery(dbF,"Select NxtNumber from NextID where NxtTable like '" + tablename + "'",null);    
    rtnID += 1;
    //db.rawQuery("update NextID set NxtNumber = '" + rtnID + "' where NxtTable like 'StationObjects'", null);
    dbF.close();
    return rtnID;
}

How do I make sure it uses the second database and not the first?
Tom

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

    You could try using the following format to open and close your database:

    private static String DB_PATH = "/data/data/PACKAGE_NAME/databases/DATABASE_NAME.db";
    private static SQLiteDatabase db;
    db = SQLiteDatabase.openDatabase(DB_PATH, null, SQLiteDatabase.OPEN_READONLY);
    // RUN YOUR QUERIES ETC
    db.close()
    

    For the case of 2 databases you would need to define 2 DB_PATHs and reference them where relevent.

    Hope this helps,
    L & L Partners

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

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.