Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are various way in populating a database. What I do is I create an <code>insert(ObjectType objectName)</code> in the DBAdapter Class. That being said, I create an object class and for this example, I'm going to use Authorized Personnel</p> <pre><code>public class AuthorizedPersonnelClass { private String _id; private String Last_Name; private String Middle_Name; private String First_Name; private String Store_ID; private String Status; private String New_Personnel; //of course insert your 2 constructors and getter setter methods here } </code></pre> <p>In my DBAdapter, I'll create the <code>insert(AuthorizedPersonnelClass authorizedPersonnel)</code> method to handle the data insertions:</p> <pre><code>public long addPersonnel(AuthorizedPersonnelClass authorizedPersonnel){ ContentValues values = new ContentValues(); values.put(AUTHORIZEDPERSONNEL_ID, authorizedPersonnel.get_id()); values.put(L_NAME_AUTHORIZED_PERSONNEL, authorizedPersonnel.getLast_Name()); values.put(M_NAME_AUTHORIZED_PERSONNEL, authorizedPersonnel.getMiddle_Name()); values.put(F_NAME_AUTHORIZED_PERSONNEL, authorizedPersonnel.getFirst_Name()); values.put(STATUS, authorizedPersonnel.getStatus()); values.put(STORE_ID, authorizedPersonnel.getStore_ID()); values.put(NEW, authorizedPersonnel.getNew_Personnel()); return this.mDB.insert(TABLE_AUTHORIZED_PERSONNEL, null, values); } </code></pre> <p>And from there, let's say I want to populate entries in my <code>onCreate()</code> function or in a button call, I'll just do as such:</p> <pre><code>//instantiate a global variable for the DBAdapter DBAdapter db = new DBAdapter(this); //then if you want to insert db.insert(new AuthorizedPersonnelClass( /*insert variables here*/ )); </code></pre> <p>Of course these values may be hard coded or user input (just use EditTexts and extract the Strings and use them there).</p> <p>Here, I used the <code>ContentValues</code> example because it's easier for beginners to use as opposed to doing a rawQuery Insert statement which may get confusing.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload