NAME- Ansari Mohd Faisal.
Dilshad
ROLL NO- 238
ASSIGNMENT-4 .
Q1-Create Following Table:
Emp (emp_no,emp_name,address,phone,salary)
Dept (dept_no,dept_name,location)
Emp-Dept is related with one-many relationship.
Create application for performing the following Operation on the table
1) Add Records into Emp and Dept table.
2) Accept Department name from User and delete employee information
which belongs
to that department.
package com.example.ass4q1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget
public class MainActivity extends AppCompatActivity {
EditText eno,ename,esalary;
Button btn;
private EmployeeDAO employeeDAO;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
eno=findViewById(R.id.editTextText);
ename=findViewById(R.id.editTextText2);
esalary=findViewById(R.id.editTextText3);
btn=findViewById(R.id.button);
employeeDAO = new EmployeeDAO(MainActivity.this);
employeeDAO.open();
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
saveEmployee();
}
private void saveEmployee() {
int empNumber=Integer.parseInt(eno.getText().toString());
String empName=ename.getText().toString();
double empSalary=Double.parseDouble(esalary.getText().toString());
Employee employee = new Employee(eno,ename,esalary);
long result=employeeDAO.addEmployee(employee);
if(result !=-1){
Toast.makeText(MainActivity.this, "Employee data added
successfully", Toast.LENGTH_SHORT).show();
else {
Toast.makeText(MainActivity.this, "Error in saving employee `",
Toast.LENGTH_SHORT).show();
protected void onDestroy(){
super.notify();
employeeDAO.close();
}
});
Employee.java
package com.example.ass4q1;
import android.widget.EditText;
public class Employee {
public Employee(EditText eno,EditText ename,EditText esalary){
public Object getEmpNumber(){return null;}
public Object getEmpName(){
return null;
public Object getEmpSalary(){
return null;
EmployeeDAO.java
package com.example.ass4q1;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.content.ContentValues;
public class EmployeeDAO {
private SQLiteDatabase database;
private DBHelper dbHelper;
private android.content.ContentValues values;
public EmployeeDAO(Context context){dbHelper=new DBHelper(context);}
public void open() throws SQLException{
database=dbHelper.getWritableDatabase();
public long addEmployee(Employee employee) {
ContentValues values=new ContentValues();
values.put((String) DBHelper.COLUMN_EMPLOYEE_NUMBER,(String)
employee.getEmpNumber());
values.put((String) DBHelper.COLUMN_EMPLOYEE_NAME,(String)
employee.getEmpName());
values.put((String) DBHelper.COLUMN_EMPLOYEE_SALARY,(String)
employee.getEmpSalary());
return database.insert(DBHelper.TABLE_EMPLOYEE,null,values);
public void close() {
dbHelper.close();}
Contentvalues.java
package com.example.ass4q1;
public enum ContentValues {
public void put(Object columnEmployeeNumber, Object empNumber){
DBHelper.java
package com.example.ass4q1;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.opengl.GLDebugHelper;
import kotlin.text.UStringsKt;
public class DBHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME="employee_database";
private static final int DATABASE_VERSION=1;
public static final Object COLUMN_EMPLOYEE_NUMBER = "eno";
public static final Object COLUMN_EMPLOYEE_NAME = "ename";
public static final Object COLUMN_EMPLOYEE_SALARY = "esalary";
public static final String TABLE_EMPLOYEE = "employee";
private static final String DB_NAME="employeedetails";
private static final int DB_Version = 1;
private Context context;
private String query;
public DBHelper(Context context) {
super(context, DB_NAME , null ,DB_Version);
public SQLiteDatabase getWritableDatabase(){return null;}
public void close(){
public void onCreate(SQLiteDatabase db){
String CREATE_TABLE_EMPLOYEE;
db.execSQL(query);
public void onUpgrade(SQLiteDatabase db,int oldversion,int newVersion){
db.execSQL("DROP TABLE IF EXISTS "+ TABLE_EMPLOYEE);
onCreate(db);