Go through the link to setup Android in Eclipse before starting the demo. Your favorite up-to-date Eclipse Versionģ. There should be JDK 6 or above version in your system.Ģ. Find the perquisites to run the application.ġ.
Install Android Application (APK file) in Android Mobile Phoneīefore starting the demo you should be ready with development environment. Create Android Virtual Device to Run the Applicationĥ. Here we will discuss step by step the creation of simple application of android using eclipse.ģ. Application LOG can be seen in console and Android Virtual Device LOG will be available in LogCat. Application can be deployed as Android Application Package (apk) file. To run the application, eclipse can be integrated with Android Virtual Device that will behave as Android Emulator. Import this page we will quick start an android application using eclipse. Although there are no syntax for run time errors when I run the code, it does not give me any output neither does it shows any message as specified in the code.
I had used the same code that you provided for sqlite database with a few modifications but unfortunately, it did not work as I expected. I'm new to android programming with only a passable background on C,C++ programming, etc. The following user-defined function is used to display message to the user: ShowMessage( " Student Management Application", " Developed By Azim") ShowMessage( " Student Details", buffer.toString()) ShowMessage( " Error", " No records found") īuffer.append( " Rollno: "+c.getString( 0)+ " \n") īuffer.append( " Name: "+c.getString( 1)+ " \n") īuffer.append( " Marks: "+c.getString( 2)+ " \n\n") Checking if no records found if(c.getCount()=0) Viewing all records if(view=btnViewAll)Ĭursor c=db.rawQuery( " SELECT * FROM student", null) ShowMessage( " Success", " Record Modified") " ' WHERE rollno='"+editRollno.getText()+ " '")
Modifying a record if(view=btnModify)ĭb.execSQL( " UPDATE student SET name='"+editName.getText()+ " ',marks='"+editMarks.getText()+ ShowMessage( " Error", " Invalid Rollno") ShowMessage( " Success", " Record Deleted") ShowMessage( " Error", " Please enter Rollno") Ĭursor c=db.rawQuery( " SELECT * FROM student WHERE rollno='"+editRollno.getText()+ " '", null) ĭb.execSQL( " DELETE FROM student WHERE rollno='"+editRollno.getText()+ " '") Checking empty roll number if(editRollno.getText().toString().trim().length()=0) ShowMessage( " Success", " Record added") ShowMessage( " Error", " Please enter all values") ĭb.execSQL( " INSERT INTO student VALUES('"+editRollno.getText()+ " ','"+editName.getText()+ Checking empty fields if(editRollno.getText().toString().trim().length()=0||ĮditName.getText().toString().trim().length()=0||ĮditMarks.getText().toString().trim().length()=0) The following code uses the db.execSQL() function to insert a student record in the student table.
In the onClick() event handler, we can write the code required to add, delete, modify and view records.
The following code shows how to create an SQLite database and a table in the database.Ĭopy Code public void onCreate(Bundle savedInstanceState)ĮditRollno=(EditText)findViewById(R.id.editRollno) ĮditName=(EditText)findViewById(R.id.editName) ĮditMarks=(EditText)findViewById(R.id.editMarks) ītnAdd=(Button)findViewById(R.id.btnAdd) ītnDelete=(Button)findViewById(R.id.btnDelete) ītnModify=(Button)findViewById(R.id.btnModify) ītnView=(Button)findViewById(R.id.btnView) ītnViewAll=(Button)findViewById(R.id.btnViewAll) ītnShowInfo=(Button)findViewById(R.id.btnShowInfo) ĭb=openOrCreateDatabase( " StudentDB", Context.MODE_PRIVATE, null) ĭb.execSQL( " CREATE TABLE IF NOT EXISTS student(rollno VARCHAR,name VARCHAR,marks VARCHAR) ") The SQLiteDatabase class from the package and the Cursor class from the android.database package provide all the functionality required for performing Data Manipulation Language (DML) and query operations on an SQLite table. For simplicity, I have created all fields of VARCHAR data type, which is a variable length character string. The application accepts a student's roll number, name and marks and adds these details to a student table.
The example application which I have created is a simple Student Management System, which allows a user to add, delete, modify and view student details.
The example application shows how to perform basic DML and query operations on an SQLite table in Android. This article assumes that the user has a working knowledge of Android and basic SQL commands. Also most of the examples assume a deep knowledge of Android and SQL. Most of the articles and demos which I have seen on the net were not very simple for a layman to understand. In this article, I have attempted to demonstrate the use of SQLite database in Android in the simplest manner possible.