0% found this document useful (0 votes)
8 views2 pages

SQLite Student Database App

The document is an Android application code that manages student records using SQLite. It allows users to add, delete, search, and view student details through a simple user interface. The application initializes a database and handles user interactions via button clicks to perform various database operations.

Uploaded by

hatehatred219
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

SQLite Student Database App

The document is an Android application code that manages student records using SQLite. It allows users to add, delete, search, and view student details through a simple user interface. The application initializes a database and handles user interactions via button clicks to perform various database operations.

Uploaded by

hatehatred219
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

package [Link].

sqlitedbapp;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].R;

public class MainActivity extends AppCompatActivity implements [Link]


{

EditText etStdntID, etStdntName, etStdntProg;


Button btAdd, btDelete, btSearch, btView;
SQLiteDatabase db;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

etStdntID = (EditText)findViewById([Link]);
etStdntName = (EditText)findViewById([Link]);
etStdntProg = (EditText)findViewById([Link]);
btAdd = (Button)findViewById([Link]);
btDelete = (Button)findViewById([Link]);
btSearch = (Button)findViewById([Link]);
btView = (Button)findViewById([Link]);

[Link](this);
[Link](this);
[Link](this);
[Link](this);

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


[Link]("CREATE TABLE IF NOT EXISTS student(stdnt_id VARCHAR, stdnt_name
VARCHAR, stdnt_prog VARCHAR);");
}

public void clearText() {


[Link]("");
[Link]("");
[Link]("");
[Link]();
}

public void showMessage(String title, String message) {


Builder builder = new Builder(this);
[Link](true);
[Link](title);
[Link](message);
[Link]();
}
@Override
public void onClick(View view) {
if (view== btAdd) {
[Link]("INSERT INTO student VALUES ('"+[Link]() +
"','"+[Link]() + "','"+[Link]() + "');");
showMessage("Success", "Record added.");
clearText();
}
else if (view== btDelete) {
Cursor c=[Link]("SELECT * FROM student WHERE stdnt_id='" +
[Link]() + "'", null);
if ([Link]()) {
[Link]("DELETE FROM student WHERE
stdnt_id='"+[Link]() + "'");
showMessage("Success", "Record Deleted.");
clearText();
}
}
else if (view==btSearch) {
Cursor c=[Link]("SELECT * FROM student WHERE stdnt_id='" +
[Link]() + "'", null);
if ([Link]()) {
StringBuffer buffer = new StringBuffer();
[Link]("Name: "+[Link](1) + "\n");
[Link]("Program: " + [Link](2) + "\n\n");
showMessage("Student Details", [Link]());
}
}
else if (view==btView) {
Cursor c=[Link]("SELECT * FROM student", null);
if([Link]()==0) {
showMessage("Error", "No records found.");
return;
}
StringBuffer buffer = new StringBuffer();
while ([Link]()) {
[Link]("ID: "+[Link](0) + "\n");
[Link]("Name: "+[Link](1) + "\n");
[Link]("Program: " + [Link](2) + "\n\n");
}
showMessage("Student Details", [Link]());
}
}
}

You might also like