Question
Consider that you are a developing an app for your university that stores the contacts details for all faculty members. Complete the DatabaseHandler class Complete
Consider that you are a developing an app for your university that stores the contacts details for all faculty members.
Complete the DatabaseHandler class
Complete the missing code (1) & (2)
Create the Contacts table (3). The static variables in the code represent the column names for the table to store the information.
Complete the DataSource class
Complete the missing code (4) & (5)
Insert a record into the Contacts table. Use any values for each table column (6)
Retrieve the contact last_name of a specific id (passed as parameter) (7)
Update the contact mobile phone of a specific user_id (8)
public class DatabaseHandler extends SQLiteOpenHelper //(1)
// Database Version private static final int DATABASE_VERSION = 1 ; // Database Name private static final String DATABASE_NAME = "seu";
// Contacts table name private static final String TABLE_CONTACTS = "Contacts";
// Contacts Table Columns names private static final String KEY_ID = "id"; private static final String KEY_FIRST_NAME = "first_name"; private static final String KEY_LAST_NAME = "last_name"; private static final String KEY_MOBILE_NUMBER = "mobile_number"; private static final String KEY_EMAIL_ID = "email_id"; private static final String KEY_USER_ID = "user_id"; private static final String KEY_PASSWORD = "password"; private static final String KEY_ROLE = "user_role"; public DatabaseHandler(Context context) {
(context, DATABASE_NAME, null, DATABASE_VERSION); //(2) }
// Creating Table Contacts @Override
public void onCreate(SQLiteDatabase db) { //(3)
String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "(" + KEY_ID + " INTEGER PRIMARY KEY," + KEY_FIRST_NAME + " TEXT," + KEY_Last_NAME + " TEXT," + KEY_MOBILE_NUMBER + " INTEGER," + KEY_EMALL_ID + " TEXT," + KEY_USER_ID + " TEXT," + KEY_PASSWORD + " TEXT," + KEY_ROLE + " TEXE" ")";
db.execSQL(CREATE_CONTACTS_TABLE);
} }
public class DataSource {
private SQLiteDatabase database ;
private DatabaseHandler dbHelper ;
public DataSource(Context context) {
___________________________________________ //(4)
}
public void open() throws SQLException {
_______________________________________________//(5)
}
// Insert one record information into Contacts Table. Put any value for each column public boolean addContact( ) { //(6)
}
// Update the contact mobile phone of the passed contact_id parameter. Put any value for the updated contact mobile phone
public boolean updateContact(int contact_id) // (7)
}
// Retrieve the contact last_name of the passed id parameter
public String getContactName(int contact_id) // (8)
{
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started