KEMBAR78
Sqlite Paper Example | PDF | Databases | Data Management Software
0% found this document useful (0 votes)
14 views5 pages

Sqlite Paper Example

The document contains an Android application code that manages a SQLite database for student records. It includes functionalities to insert, view, and delete records from the database. The UI consists of buttons for each action and a TextView to display the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views5 pages

Sqlite Paper Example

The document contains an Android application code that manages a SQLite database for student records. It includes functionalities to insert, view, and delete records from the database. The UI consists of buttons for each action and a TextView to display the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

package com.example.

sq;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;

import android.database.Cursor;

import android.database.sqlite.SQLiteDatabase;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

import android.widget.Toast;

import org.w3c.dom.Text;

public class MainActivity extends AppCompatActivity {

Button b1,b2,b3;

TextView t;

SQLiteDatabase db;

String d1,d2,d3,d4,d5;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

b1=findViewById(R.id.b1);

b2=findViewById(R.id.b2);

b3=findViewById(R.id.b3);

t=findViewById(R.id.t);

db=openOrCreateDatabase("student", Context.MODE_PRIVATE, null);

db.execSQL("CREATE TABLE IF NOT EXISTS stud1(name VARCHAR(20),rollno NUMBER,marks


NUMBER,branch VARCHAR(20),per NUMBER);");

public void insert(View v){

db.execSQL("INSERT INTO stud1 VALUES('ajinkya',10,890,'CM',90);");

db.execSQL("INSERT INTO stud1 VALUES('abc',11,800,'CM',91);");

db.execSQL("INSERT INTO stud1 VALUES('pqr',10,870,'CM',78);");

db.execSQL("INSERT INTO stud1 VALUES('ijk',10,890,'CM',80);");

db.execSQL("INSERT INTO stud1 VALUES('lmn',10,690,'CM',67);");

Toast.makeText(this,"record inserted", Toast.LENGTH_LONG).show();

public void view(View v){

String s6;
int total = 0, n;

Cursor C3=db.rawQuery("select * from stud1;",null);

C3.moveToFirst();

if(!C3.isAfterLast())

do{

s6 = C3.getString(0)+C3.getInt(1)+C3.getInt(2)+C3.getString(3)+C3.getInt(4);

t.append("\n" + s6);

}while(C3.moveToNext());

public void delete(View v){

db.execSQL("DELETE FROM stud1 where name="+"'ajinkya';");

Toast.makeText(this,"record deleted", Toast.LENGTH_LONG).show();

}
<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout
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"

tools:context=".MainActivity">

<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="insert"

android:onClick="insert"

android:id="@+id/b1"/>

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="view"

android:onClick="view"

android:id="@+id/b2"/>
<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="delete"

android:onClick="delete"

android:id="@+id/b3"/>

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/t"/>

</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

You might also like