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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:04:57+00:00 2026-05-31T20:04:57+00:00

I am trying to write to a table in my sqlite database in android

  • 0

I am trying to write to a table in my sqlite database in android the code I am using is as follows:

DBH = new DatabaseHelper(this);
    try {
        DBH.createDataBase();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    DBH.getWritableDatabase().rawQuery("insert into profile (_id, FirstName) values (1, 'Dave')", null);
    DBH.close();

DBH is my database helper class and it creates the database just fine and I’ve even been able to read from the database so i know its there. The table im trying to write to is profile and i am certain that it does in fact exist but every time i run this i get this error:

sqlite returned: error code = 1, msg = no such table: profile

I’ve tried reading from this table and have been able to get results so I’m pretty much stumped. Anyone got any ideas?

Edit: As requested this is my Database helper class

public class DatabaseHelper extends SQLiteOpenHelper {

private static String DB_PATH = "/data/data/com.ProjectZeus.FitnessWire/databases/";
private static String DB_NAME = "fitnesswire.db";
private SQLiteDatabase myDB;
private Context  myContext;

public DatabaseHelper(Context context) {
    super(context,DB_NAME, null, 1);
    this.myContext = context;   
}

public void createDataBase() throws IOException{
    boolean check = checkDataBase();
    if(check){
        //Log.e("Check", "Database exists");
    }else{
        this.getReadableDatabase();

        try{
            copyDataBase();
        }catch(Exception e){
            throw new Error("Error copying database");
        }
    }
}


private void copyDataBase() throws IOException {
    InputStream myInput = myContext.getAssets().open(DB_NAME);

    String outFileName = DB_PATH + DB_NAME;

    OutputStream myOutput = new FileOutputStream(outFileName);

    byte [] buffer = new byte[1024];
    int length;
    while((length = myInput.read(buffer))>0){
        myOutput.write(buffer,0,length);
    }

    myOutput.flush();
    myOutput.close();
    myInput.close();

}

private boolean checkDataBase() {
    SQLiteDatabase checkdb = null;
    try{
        String myPath= DB_PATH + DB_NAME;
        checkdb = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
    }catch(SQLiteException e){
        Log.e("checkDataBase()", "Database doesntexist yet");
    }

    if(checkdb != null){
        checkdb.close();
    }

    return checkdb != null ? true : false ;
}

public void openDataBase() throws SQLException {
    String myPath = DB_PATH + DB_NAME;
    myDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
}

@Override
public synchronized void close(){
    if(myDB != null){
        myDB.close();
    }
    super.close();
}

@Override
public void onCreate(SQLiteDatabase db) {


}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub

}

}

  • 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-31T20:04:58+00:00Added an answer on May 31, 2026 at 8:04 pm

    You should use db.execSQL() instead of db.rawQuery() since insert is no query (only SELECT is)

    There is a lot of magic going on in rawQuery() – it may change the statement before executed by the database and also tries to build a Cursor out of the result. Some part in that process seems to fail.

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

Sidebar

Related Questions

I'm trying to test a simple SQLite database using Robolectric in my Android application.
I'm new to Android and SQLite, too. I'm trying to write a method where
I guess many people already read this article: Using your own SQLite database in
I am trying to write a query for retrieving data from SQLite database. I
I'm having trouble with my sqlite database. I'm trying to write an query that
I'm trying to write a SQLite query in Android where I select all rows
I am trying to store data in created SQLite database. Here is the code
I'm not a database guy (as this question will show). I'm trying to write
I am trying to write some vba code in Excel to query a table
i´m trying to write a little script for writting a sqlite table from an

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.