Develop an application that makes use of database
1.activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TableLayout
android:layout_width="395dp"
android:layout_height="715dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/textView"
android:layout_width="48dp"
android:layout_height="16dp"
android:text="RollNo"
tools:layout_editor_absoluteX="176dp"
tools:layout_editor_absoluteY="29dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<EditText
android:id="@+id/rollno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
tools:layout_editor_absoluteX="81dp"
tools:layout_editor_absoluteY="42dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="enter your @string/app_name"
tools:layout_editor_absoluteX="159dp"
tools:layout_editor_absoluteY="87dp"
tools:text="enter your @string/app_name" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<EditText
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
tools:layout_editor_absoluteX="108dp"
tools:layout_editor_absoluteY="100dp" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Insert"
tools:layout_editor_absoluteX="144dp"
tools:layout_editor_absoluteY="164dp"
android:onClick="insert_data"/>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete"
tools:layout_editor_absoluteX="138dp"
tools:layout_editor_absoluteY="205dp"
android:onClick="delete_data"/>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="update"
tools:layout_editor_absoluteX="138dp"
tools:layout_editor_absoluteY="205dp"
android:onClick="update_data"/>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
tools:layout_editor_absoluteX="165dp"
tools:layout_editor_absoluteY="249dp" />
</TableLayout>
</[Link]>
[Link]
package [Link].cse_bii_exno5;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
public void insert_data(View view)
{
SQLiteDatabase db=[Link]("student",MODE_PRIVATE,null);
[Link]("CREATE TABLE IF NOT EXISTS biodata(rollno VARCHAR,name
VARCHAR)");
EditText rollno1=(EditText)findViewById([Link]);
EditText name1=(EditText)findViewById([Link]);
TextView tv=(TextView)findViewById([Link]);
String txt_rollno;
String txt_name;
txt_rollno=[Link]().toString();
txt_name=[Link]().toString();
[Link]("INSERT INTO biodata(rollno,name) values('"+ txt_rollno +"','"+ txt_name
+"')");
Cursor c=[Link]("select * from biodata",null);
[Link]("\n DETAILS AFTER INSERTING :\n");
while([Link]())
{
[Link]("RollNO: "+[Link](0) + " Name: " + [Link](1) + "\n");
[Link]("-------------------------\n");
}
}
public void delete_data(View view)
{
SQLiteDatabase db=[Link]("student",MODE_PRIVATE,null);
[Link]("CREATE TABLE IF NOT EXISTS biodata(rollno VARCHAR,name
VARCHAR)");
EditText rollno1=(EditText)findViewById([Link]);
EditText name1=(EditText)findViewById([Link]);
TextView tv=(TextView)findViewById([Link]);
String txt_rollno;
String txt_name;
txt_rollno=[Link]().toString();
txt_name=[Link]().toString();
[Link]("delete from biodata where rollno='"+ txt_rollno +"'");
Cursor c=[Link]("select * from biodata",null);
[Link]("\n DETAILS AFTER DELETING :\n");
while([Link]())
{
[Link]("RollNO: "+[Link](0) + " Name: " + [Link](1) + "\n");
[Link]("-------------------------\n");
}
}
public void update_data(View view)
{
SQLiteDatabase db=[Link]("student",MODE_PRIVATE,null);
[Link]("CREATE TABLE IF NOT EXISTS biodata(rollno VARCHAR,name
VARCHAR)");
EditText rollno1=(EditText)findViewById([Link]);
EditText name1=(EditText)findViewById([Link]);
TextView tv=(TextView)findViewById([Link]);
String txt_rollno;
String txt_name;
txt_rollno=[Link]().toString();
txt_name=[Link]().toString();
[Link]("update biodata set name='"+ txt_name + "' where rollno='"+ txt_rollno +"'");
Cursor c=[Link]("select * from biodata",null);
[Link]("\n DETAILS AFTER DELETING :\n");
while([Link]())
{
[Link]("RollNO: "+[Link](0) + " Name: " + [Link](1) + "\n");
[Link]("-------------------------\n");
}
}
}