String - XML: Resources String String String

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

STRING.

XML

<resources>
<string name="app_name">MySQLite</string>
<string name="create">CREATE TABLE IF NOT EXISTS tbl_student
(stu_id INTEGER PRIMARY KEY AUTOINCREMENT,
stu_name VARCHAR(50),
stu_add VARCHAR(100) NULL,
stu_gpa FLOAT);
</string>
<string name="insert">
INSERT INTO tbl_student
VALUES ('SOK visual',
'phnon penh', 4.0);

</string>
<string name="select">SELECT * FROM tbl_student</string>

</resources>

MAIN ACTIVITY

package com.example.rehan.mysqlite;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

SQLiteDatabase db = openOrCreateDatabase("Test", MODE_PRIVATE, null);

db.execSQL(getString(R.string.create));
db.execSQL(getString(R.string.insert));
Cursor result = db.rawQuery(getString(R.string.select), null );
result.moveToFirst();
while(result.isAfterLast()!= true){
result.getInt(0);
result.getString(1);
result.getString(2);
result.getFloat(3);

result.moveToNext();
}

}
}

You might also like