0% found this document useful (0 votes)
4 views5 pages

SQLite DB

The document outlines the development of three applications using SQLite databases to manage customer, employee, and student details. Each application includes Java and XML code for creating, updating, and retrieving records based on unique identifiers. The applications demonstrate basic CRUD operations in Android development with SQLite integration.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

SQLite DB

The document outlines the development of three applications using SQLite databases to manage customer, employee, and student details. Each application includes Java and XML code for creating, updating, and retrieving records based on unique identifiers. The applications demonstrate basic CRUD operations in Android development with SQLite integration.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

5.

SQLite DB

1️Develop an application to store customer’s details like,


customer-id, customer-name, mobile number, address, pin-
code and retrieve customer information using customer-id
in SQLite databases (Winter 2022)
XML ( activity_main.xml )

XML
1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2 android:layout_width="match_parent"
3 android:layout_height="match_parent"
4 android:orientation="vertical"
5 android:gravity="center">
6 <EditText
7 android:id="@+id/id"
8 android:layout_width="wrap_content"
9 android:layout_height="wrap_content"
10 android:hint="Customer ID"/>
11 <EditText
12 android:id="@+id/name"
13 android:layout_width="wrap_content"
14 android:layout_height="wrap_content"
15 android:hint="Name"/>
16 <Button
17 android:id="@+id/add"
18 android:layout_width="wrap_content"
19 android:layout_height="wrap_content"
20 android:text="Add"/>
21 <Button
22 android:id="@+id/get"
23 android:layout_width="wrap_content"
24 android:layout_height="wrap_content"
25 android:text="Get"/>
26 <TextView
27 android:id="@+id/tv"
28 android:layout_width="wrap_content"
29 android:layout_height="wrap_content"
30 android:text=""/>
31 </LinearLayout>

Java ( MainActivity.java )

Java
1 package com.example.dbapp;
2 import android.os.*;
3 import android.widget.*;
4 import android.database.sqlite.*;
5 import android.database.*;
6 import androidx.appcompat.app.*;
7
8 public class MainActivity extends AppCompatActivity {
9 EditText id,name; Button add,get; TextView tv; SQLiteDatabase db;
10 protected void onCreate(Bundle s){
11 super.onCreate(s);
12 setContentView(R.layout.activity_main);
13 id=findViewById(R.id.id); name=findViewById(R.id.name);
14 add=findViewById(R.id.add); get=findViewById(R.id.get); tv=findViewById(R.id.tv);
15 db=openOrCreateDatabase("custdb",MODE_PRIVATE,null);
16 db.execSQL("create table if not exists cust(id text,name text)");
17 add.setOnClickListener(v-> db.execSQL("insert into cust
values('"+id.getText()+"','"+name.getText()+"')"));
18 get.setOnClickListener(v-> {
19 Cursor c=db.rawQuery("select * from cust where id='"+id.getText()+"'",null);
20 if(c.moveToNext()) tv.setText(c.getString(1)); else tv.setText("Not Found");
21 });
22 }
23 }

2️Develop an application to update a record of an employee


whose emp.id is ‘E101’ in SQLite database. Change
employee name from “PQR” to “XYZ”. Also display the
updated record. (Write .java and .xml files) (Winter 2023)
Java ( MainActivity.java )

Java
1 package com.example.dbapp;
2 import android.os.*;
3 import android.widget.*;
4 import android.database.sqlite.*;
5 import android.database.*;
6 import androidx.appcompat.app.*;
7
8 public class MainActivity extends AppCompatActivity {
9 Button u; TextView t; SQLiteDatabase db;
10 protected void onCreate(Bundle s){
11 super.onCreate(s);
12 setContentView(R.layout.activity_main);
13 u=findViewById(R.id.upd); t=findViewById(R.id.tv);
14 db=openOrCreateDatabase("empdb",MODE_PRIVATE,null);
15 db.execSQL("create table if not exists emp(id text,name text)");
16 db.execSQL("insert into emp values('E101','PQR')");
17 u.setOnClickListener(v-> {
18 db.execSQL("update emp set name='XYZ' where id='E101'");
19 Cursor c=db.rawQuery("select * from emp where id='E101'",null);
20 if(c.moveToNext()) t.setText(c.getString(0)+" "+c.getString(1));
21 });
22 }
23 }

XML ( activity_main.xml )

XML
1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2 android:layout_width="match_parent"
3 android:layout_height="match_parent"
4 android:orientation="vertical"
5 android:gravity="center">
6 <Button
7 android:id="@+id/upd"
8 android:layout_width="wrap_content"
9 android:layout_height="wrap_content"
10 android:text="Update"/>
11 <TextView
12 android:id="@+id/tv"
13 android:text=""
14 android:layout_width="wrap_content"
15 android:layout_height="wrap_content"/>
16 </LinearLayout>

3️Develop an application to store student details like roll


no, name, marks and retrive student information using roll
no. in SQLite database. (Write java and xml file) (Winter
2024)
XML ( activity_main.xml )

XML
1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2 android:layout_width="match_parent"
3 android:layout_height="match_parent"
4 android:orientation="vertical"
5 android:gravity="center">
6 <EditText
7 android:id="@+id/r"
8 android:layout_width="wrap_content"
9 android:layout_height="wrap_content"
10 android:hint="Roll No"/>
11 <EditText
12 android:id="@+id/n"
13 android:layout_width="wrap_content"
14 android:layout_height="wrap_content"
15 android:hint="Name"/>
16 <EditText
17 android:id="@+id/m"
18 android:layout_width="wrap_content"
19 android:layout_height="wrap_content"
20 android:hint="Marks"/>
21 <Button
22 android:id="@+id/add"
23 android:layout_width="wrap_content"
24 android:layout_height="wrap_content"
25 android:text="Add"/>
26 <Button
27 android:id="@+id/get"
28 android:layout_width="wrap_content"
29 android:layout_height="wrap_content"
30 android:text="Get"/>
31 <TextView
32 android:id="@+id/tv"
33 android:layout_width="wrap_content"
34 android:layout_height="wrap_content"
35 android:text=""/>
36 </LinearLayout>

Java ( MainActivity.java )

Java
1 package com.example.dbapp;
2 import android.os.*;
3 import android.widget.*;
4 import android.database.sqlite.*;
5 import android.database.*;
6 import androidx.appcompat.app.*;
7
8 public class MainActivity extends AppCompatActivity {
9 EditText r,n,m; Button add,get; TextView t; SQLiteDatabase db;
10 protected void onCreate(Bundle s){
11 super.onCreate(s);
12 setContentView(R.layout.activity_main);
13 r=findViewById(R.id.r); n=findViewById(R.id.n); m=findViewById(R.id.m);
14 add=findViewById(R.id.add); get=findViewById(R.id.get); t=findViewById(R.id.tv);
15 db=openOrCreateDatabase("studdb",MODE_PRIVATE,null);
16 db.execSQL("create table if not exists stud(rno text,name text,marks text)");
17 add.setOnClickListener(v-> db.execSQL("insert into stud
values('"+r.getText()+"','"+n.getText()+"','"+m.getText()+"')"));
18 get.setOnClickListener(v-> {
19 Cursor c=db.rawQuery("select * from stud where rno='"+r.getText()+"'",null);
20 if(c.moveToNext()) t.setText(c.getString(1)+" "+c.getString(2)); else t.setText("Not
Found");
21 });
22 }
23 }
© 2025 by 25_Daksh ♔
These notes and study materials are the intellectual property of 25_Daksh (♔). Unauthorized use, reproduction,
distribution, or modification is strictly prohibited.

For permissions or inquiries, please contact the creator directly: [email protected]

TRACKING ACTIVE • This document contains digital markers and unique identifiers

You might also like