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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:49:34+00:00 2026-06-13T12:49:34+00:00

I have problem with sqlite database. I want create database in android with existing

  • 0

I have problem with sqlite database. I want create database in android with existing records.
I create database:

public class PrzyslowiaArabskie  {

private static final String TABLE_NAME = "tabela_przyslowia";
private static final String DATABASE_NAME = "przyslowiadb";
private static final int DATABASE_VERSION = 1;
public static final String KEY_ID = "id";
public static final String KEY_PRZYSLOWIE = "przyslowie";

private DbHelper myHelper;
private final Context myContext;
private SQLiteDatabase myDatabase;




private static class DbHelper extends SQLiteOpenHelper {

    public DbHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
         db.execSQL("CREATE TABLE " + TABLE_NAME + " (" + 
                   KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + 
                 KEY_PRZYSLOWIE + " TEXT NOT NULL);" );


    } 

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);

        onCreate(db);
    }

}
public PrzyslowiaArabskie(Context c) {
    myContext = c;
}
public PrzyslowiaArabskie open() {
    myHelper = new DbHelper(myContext);
    myDatabase = myHelper.getWritableDatabase();
    return this;
}
public void close() {
    myHelper.close();
}
public long createEntry(String przyslowie) {
    ContentValues cv = new ContentValues();
    cv.put(KEY_PRZYSLOWIE, przyslowie);
    return myDatabase.insert(TABLE_NAME, null, cv);

}
public String getData() {
    // TODO Auto-generated method stub
    String[] columns = new String[] { KEY_ID, KEY_PRZYSLOWIE };
    Cursor c = myDatabase.query(TABLE_NAME, columns, null, null, null, null, null);
    String result = "";

    int iRow = c.getColumnIndexOrThrow(KEY_ID);
    int iPrzyslowie = c.getColumnIndexOrThrow(KEY_PRZYSLOWIE);


    for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
        result = result + c.getString(iRow) + " " + c.getString(iPrzyslowie) + "\n";
    }

    return result;
}

}

What can I do if I want that create database with existing records. How to add records together with create database?

  • 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-13T12:49:35+00:00Added an answer on June 13, 2026 at 12:49 pm

    You just need to insert values in the onCreate() method, after you’ve created the table:

    @Override
    public void onCreate(SQLiteDatabase db) {
      db.execSQL("CREATE TABLE " + TABLE_NAME + " ("
          + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
          + KEY_PRZYSLOWIE + " TEXT NOT NULL);" );
    
      ContentValues values = new ContentValues();
      values.put(KEY_PRZYSLOWIE , "My text");
    
      db.insert(TABLE_NAME, null, values);
      // ... etc...
    } 
    

    As a side note, if your database is more complicated than this simple example, you might want to delegate table creation and initialization to other methods or even classes.

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

Sidebar

Related Questions

I was newbie in using sqlite database android. and now I have a problem
I have a problem when pushing data to my sqlite database in iphone application.
Hi all im using a sqlite helper class, but i have a little problem
I have created a database using SQLite. I want to update the value of
I want to insert some data to mydatabase.sqlite but I have a problem. There
I have some problem with reading from sqlite3 database. -(void) readMessengesFromDatabase { sqlite3 *database;
I have a problem. I have two sqlite files and I need (with PHP)
I have a SQLite database, and several tables within that datbase. I am developing
Today I use SQLite and send a database-file with the project. However I want
i have got a problem with my SQL Statement: Table structure: CREATE TABLE tags

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.