Download presentation
Presentation is loading. Please wait.
Published byViolet Haynes Modified over 9 years ago
1
DKU-MUST Mobile ICT Education Center 12. Data Storage and Management
2
Page 2 Goal Learn the basic concepts of database. Learn how to use the SQLite. App development using SQLite. Learn how to use the SQLite GUI Tool.
3
Page 3 1. SQLite Basic ▶ Basic concepts of database Overview the SQLite SQLite is a relational database management system contained in a small C programming library. In contrast to other database management systems, SQLite is not a separate process that is accessed from the client application, but an integral part of it. SQLite is ACID-compliant and implements most of the SQL standard, using a dynamically and weakly typed SQL syntax that does not guarantee the domain integrity. SQLite is a popular choice as embedded database for local/client storage in application software such as web browsers. It is arguably the most widely deployed database engine, as it is used today by several widespread browsers, operating systems, and embedded systems, among others. SQLite has many bindings to programming languages.
4
Page 4 1. SQLite Basic ▶ Basic concepts of database Database definition A database is an organized collection of data. The data is typically organized to model relevant aspects of reality(for example, the availability of rooms in hotels), in a way that supports processes requiring this information(for example, finding a hotel with vacancies). Database management systems (DBMSs) are specially designed applications that interact with the user, other applications, and the database itself to capture and analyze data. A general-purpose database management system(DBMS) is a software system designed to allow the definition, creation, querying, update, and administration of databases. Well-known DBMSs include MySQL, PostgreSQL, SQLite, Microsoft SQL Server, Microsoft Access, Oracle, SAP, dBASE, FoxPro, and IBM DB2. A database is not generally portable across different DBMS, but different DBMSs can inter-operate by using standards such as SQL and ODBC or JDBC to allow a single application to work with more than one database.
5
Page 5 Relational Database A relational database is a database that has a collection of tables of data items, all of which is formally described and organized according to the relational model. The term is in contrast to only one table as the database, and in contrast to other models which also have many tables in one database. In the relational model, each table schema must identify a primary column used for identifying a row called the primary key. Tables can relate by using a foreign key that points to the primary key. The relational model offers various levels of refinement of the table relations called database normalization. (See Normalization below.) The database management system (DBMS) of a relational database is called an RDBMS, and is the software of a relational database. The relational database was first defined in June 1970 by Edgar Codd, of IBM's San Jose Research Laboratory. Codd's view of what qualifies as an RDBMS is summarized in Codd's 12 rules. A relational database has become the predominant choice in storing data. Other models besides the relational model include the hierarchical database model and the network model. 1. SQLite Basic ▶ Basic concepts of database
6
Page 6 Database-related terms 1. SQLite Basic ▶ Basic concepts of database Database Naver Database A DatabaseB Database Table B Table C Table Column Name Member Table Column Row
7
Page 7 Steps to build the database in the SQLite ① Create the Database ↓ ② Create the Table ↓ ③ Input the Data ↓ ④ Select/Using the Data 1. SQLite Basic ▶ Build a database in SQLite Step. 1 Step. 2 Step. 3 Install the DBMS (Already Installed) Install the DBMS (Already Installed) Building the Database Building the Database Using the data that built in application Using the data that built in application
8
Page 8 [Practice 12-1] To build a database (1/7) To build a Database Build a database in SQLite Access the command prompt Project Info. Project Name : Project12_1 Package Name : com.cookandroid.project12_1 build SDK : Goolge API 15 or 16 Minimum Required SDK : API 15 or 16 Activity Name : Project12_1Activity Layout Name : main Title : Project12_1 First, Run the project Because AVD is Running 이번 실습은 프로젝트를 실행해서 우선 AVD 를 가동해야 한다. 1. SQLite Basic ▶ Build a database in SQLite
9
Page 9 Run the adb.exe Run the command prompt → Run the adb.exe Adb.exe path is “androidsdk\platform-tools\” 1. SQLite Basic ▶ Build a database in SQLite [Practice 12-1] To build a database (2/7)
10
Page 10 Ready access to SQLite 1. SQLite Basic ▶ Build a database in SQLite [Practice 12-1] To build a database (3/7)
11
Page 11 ① Create a Database 1. SQLite Basic ▶ Build a database in SQLite [Practice 12-1] To build a database (4/7)
12
Page 12 ② Create a table 1. SQLite Basic ▶ Build a database in SQLite [Practice 12-1] To build a database (5/7)
13
Page 13 ③ Input the Data 1. SQLite Basic ▶ Build a database in SQLite [Practice 12-1] To build a database (6/7)
14
Page 14 ④ Using and select… the data 1. SQLite Basic ▶ Build a database in SQLite [Practice 12-1] To build a database (7/7)
15
Page 15 Create the myDB(Database), and Create the table [Self Test 12-1] 1. SQLite Basic ▶ Build a database in SQLite Product NamePrice Date of Manufacture Manufacturing Company Remaining quantity TV1002012.07.22.Samsung55 Computer1502013.05.05.LG7 Monitor502014.09.09.Daewoo33 Printer802013.05.20.HP24
16
Page 16 SQLite behavior for the development of Android App Using the SQLiteOpenHelper Class, SQLiteDatabase Class, Cursor Interface 2. Using the SQLite ▶ SQLite Programming SQLiteOpenHelper Class SQLite Database SQLite Database Inherit override Inherit override SQLiteDatabase Class Cursor Interface Create the Database Create the Table Execution of the SQL Query Move the Cursor
17
Page 17 Mainly used the method in each class 2. Using the SQLite ▶ SQLite Programming Class or InterfaceMethodMain purpose SQLiteOpenHelper Class ConstructorCreate the Database onCreate()Create the Table onUpgrade()Delete the Table and recreate getReadableDatabase()Open read-only DB, return the SQLiteDatabase getWritableDatabase() Open for reading and writing DB, Return the SQLiteDatabase SQLiteDatabase Class execSQL()Execute the SQL Query(Insert, Update, Delete) close()Close the DB Query(), rawQuery()After running, the select cursor returns Cursor Interface moveToFirst()Move to the first row of the cursor moveToLast()Move to the last row of the cursor moveToNext()Move to the next row of the cursor
18
Page 18 [Practice 12-2] Create the DB management singer name App (1/9) Create the singer name DB management App Insert and Select the name of Singer group in the Database Project Info. Project Name : Project12_2 Package Name : com.cookandroid.project12_2 build SDK : Goolge API 15 or 16 Minimum Required SDK : API 15 or 16 Activity Name : Project12_2Activity Layout Name : main Title : Project12_2 2. Using the SQLite ▶ SQLite Programming
19
Page 19 Design the Screen LinearLayou 1 : 1 TextView, 1 EditText(edtName) LinearLayou 2 : 1 TextView, 1 EditText(edtNumber) LinearLayou 3 : 3 Button(btnInit, btnInsert, btnSelect) LinearLayou 4 : 2 EditText(edtNameResult, edtNumberResult) 2. Using the SQLite ▶ SQLite Programming [Practice 12-2] Create the DB management singer name App (2/9)
20
Page 20 Java Coding 1 Define a class that inherits from SQLiteOpenHelper class Modify the constructor 2. Using the SQLite ▶ SQLite Programming [Practice 12-2] Create the DB management singer name App (3/9)
21
Page 21 Java Coding 2 : Coding the onCreate( ) and onUpgrade( ) method of the myDBHelper class onCreate( ) method : Coding the create a table code onUpgrade( ) method : Coding the delete table and recreate table code 2. Using the SQLite ▶ SQLite Programming [Practice 12-2] Create the DB management singer name App (4/9)
22
Page 22 Java coding 3 : Coding the main Activity class The newly created myDBHelper class variables / Four variables respond to EditText The three variables respond to the Button / SQLiteDatabase Class variabless 2. Using the SQLite ▶ SQLite Programming [Practice 12-2] Create the DB management singer name App (5/9)
23
Page 23 Java coding 4 Coding the Listener to run, when you click the 2. Using the SQLite ▶ SQLite Programming [Practice 12-2] Create the DB management singer name App (6/9)
24
Page 24 Java coding 5 When you click the, Coding the Listener for input the value of the EditText 2. Using the SQLite ▶ SQLite Programming [Practice 12-2] Create the DB management singer name App (7/9)
25
Page 25 Java Coding 6 When you click the, coding the Listener for show the all data in the table. (printed on the bottom of the EditText) 2. Using the SQLite ▶ SQLite Programming [Practice 12-2] Create the DB management singer name App (8/9)
26
Page 26 Run and the results confirm After running the project, enter the required information and confirm the results At the command prompt, confirm the contents of the groupDB 2. Using the SQLite ▶ SQLite Programming [Practice 12-2] Create the DB management singer name App (9/9)
27
Page 27 Update the [Practice 12-2] Add a and button ① 이름에 그룹 이름과 변경된 인원을 입력한 후 을 클릭하면 해당 그룹의 인원이 변경되도록 한다. ② 이름에 그룹 이름을 입력하고 를 클릭하면 해당 그룹의 행이 삭제되도록 한다. ③,, 를 클릭하면 그 결과가 즉시 화면에 보이도록 한다. [Self Test 12-2] 2. Using the SQLite ▶ SQLite Programming
28
Page 28 SQLite Database Browser (1/2) : Create a database and table 2. Using the SQLite ▶ Using SQLite GUI Tool
29
Page 29 SQLite Database Browser (2/2): Input the data 생성한 데이터베이스 파일은 DDMS 를 통해 AVD 에 넣어서 (Push) 사용할 수 있다. 2. Using the SQLite ▶ Using SQLite GUI Tool
30
Page 30 [ 실습 12-2] 의 groupDB 데이터베이스 파일을 DDMS 를 이용해서 AVD 에서 PC 로 가져 온 (Pull) 후 수정한다. SQLite Database Browser 에서 가수 그룹 이름을 모두 한글로 고치고 가수그룹을 몇 개 더 입력해보자. 그리고 AVD 에 다시 넣은 (Push) 후 [ 실습 12-2] 를 실행해서 데이터가 잘 조회되는지 확인한다. [Self Test 12-3] 2. Using the SQLite ▶ Using SQLite GUI Tool
31
Page 31 SQLite Developer 2. Using the SQLite ▶ Using SQLite GUI Tool
32
Page 32 Summary 1.Database-related terms Data, Table, Database, DBMS, column(column or field), column name, Type of data(data type), row, SQL 2.The database type of SQL statements Create a table : CREATE TABLE Input the data : INSERT INTO Update the data : UPDATE Delete the data : DELETE FROM Select the data : SELECT 3.SQLite Progamming Using the SQLiteOpenHelper Class, SQLiteDatabase Class and Cursor Interface
33
DKU-MUST Mobile ICT Education Center
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.