0

I am developing an android app and I have to store some data using SQLite db . I have 8 accounts having following elements

  • Name (String)
  • Control Type (int)
  • Site (String)
  • Username (string)
  • Password (String)

Now I would like to store, access and modify them using SQLite. I have defined them in a class as follows

public class accountsDB {

//private variables
int _id;
int _control_type
boolean _empty;
String _site_name;
String _site_phone_number;
String _user_name;
String _pass;


// Empty constructor
public accountsDB(){

}

I am using _empty boolean value to check if the account has been added or is empty and I can add new account here if required

I am confused for two things:

  1. I need to have 8 copies of this class so I can save,read and edit account [1-8]
  2. How can I fill default values for _id and _empty when this db will first be created.

I am new to android and havent used the SQLite DB method to save data. Thanks in Advance

dmSherazi
  • 3,743
  • 5
  • 37
  • 62
  • 1
    If your goal is to allow max 8 entries into the accounts table, you can check the record count before inserting new record/account. – jagmohan Nov 05 '13 at 07:58

2 Answers2

1
  1. For id, set it as primary key and auto increment, so you won't need to keep a track of the id.
  2. For boolean value _empty, store a default value as 0. See this post for storing boolean values. Store boolean value in SQLite
Community
  • 1
  • 1
Bette Devine
  • 1,196
  • 1
  • 9
  • 23
1
  1. Please explain in detail.
  2. _id is autoincement (no need use default value), for empty you may use SQL parameter - DEFAULT (How to add default value in SQLite?, Set default value of an integer column SQLite)
Community
  • 1
  • 1
artemiygrn
  • 1,036
  • 7
  • 18