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

Mad 3.4

The document describes an Android application that uses SQLite as a backend database. It includes code snippets for the android_main.xml layout file and the Database.java file that implements SQLiteOpenHelper to manage the database. The application allows users to register by storing their details in a database table and also implements a login function to authenticate users.

Uploaded by

Aman Singh
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)
69 views5 pages

Mad 3.4

The document describes an Android application that uses SQLite as a backend database. It includes code snippets for the android_main.xml layout file and the Database.java file that implements SQLiteOpenHelper to manage the database. The application allows users to register by storing their details in a database table and also implements a login function to authenticate users.

Uploaded by

Aman Singh
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

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 3.4

Student Name: Utkarsh Singh UID: 21BCS6883


Branch: CSE Section/Group:21BCS-FL602/B
Semester: 06th Date of Performance: 10/04/2024
Subject Name: MAD Lab Subject Code: 21CSH-355

1. Aim: To create an Android application using SQLite as a Backend.

2. Objective:
The objective of an Android application using Fragments can be is to
register user in the mobile application and store the data in the user details
in the database table using the SQLite database services provided by the
android device which can be saved locally.

3. Code:

Code for android_main.xml-

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/backwelcome"
tools:context=".Home">

<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="20dp"
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

android:layout_marginTop="90dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:columnCount="2"
android:rowCount="2">

<androidx.cardview.widget.CardView
android:id="@+id/myprofile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_rowWeight="1"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_margin="10dp"
app:cardBackgroundColor="@color/peachDark"
app:cardCornerRadius="20dp"
app:cardElevation="8dp"
app:cardUseCompatPadding="true">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:orientation="vertical">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/user64" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My Profile"
android:textSize="20sp"
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

android:textAlignment="center"
android:textColor="@color/black"
android:textStyle="bold" />
</LinearLayout>

</androidx.cardview.widget.CardView>

Code for Database.java file-

package com.example.workconnect;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class Database extends SQLiteOpenHelper {

public Database(@Nullable Context context, @Nullable String name, @Nullable


SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);

@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
String qry1 = "create table users(username text, email text, password text)";
sqLiteDatabase.execSQL(qry1);
}

@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

public void register(String username, String email, String password){


ContentValues cv = new ContentValues();
cv.put("username",username);
cv.put("email",email);
cv.put("password",password);
SQLiteDatabase db = getWritableDatabase();
db.insert("users",null,cv);
db.close();
}

public int login(String username, String password){


int result = 0;
String str[] = new String[2];
str[0]=username;
str[1]=password;
SQLiteDatabase db = getReadableDatabase();
Cursor c = db.rawQuery("select * from users where username = ? and password = ? ",str);
if(c.moveToFirst()){
result= 1;
}
return result;
}

}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

4. Output:

5. Learning Outcomes:
1. How to use database in Java
2. How to work with android_main.xml file
3. How to use SQLite and SQLiteOpenHelper in Android Development.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy