Database Programming Code Dissection. Layered Approach Presentation (Activity) DbSampleActivity.java DataAccess (DataSource) CommentsDataSource.java MySQLiteHelper.java.

Slides:



Advertisements
Similar presentations
Programming with Android: Data management
Advertisements

Query Methods (SQL). What is SQL A programming language for databases. SQL (structured Query Language) It allows you add, edit, delete and run queries.
ListView Examples. Basic Steps for Creating a Listview 1.Create a layout (e.g., a LinearLayout), with elements for –the ListView (
SQLite in Mobile Apps by Dan Youberg. Overview Many well known applications and Internet browsers use SQLite due to its very small size (~250 Kb). Also.
Chapter 4B: More Advanced PL/SQL Programming
1 JDBC Java Database Connectivity. 2 c.pdf
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
SQLLite and Java CS-328 Dick Steflik. SQLLite Embedded RDBMS ACID Compliant Size – about 257 Kbytes Not a client/server architecture –Accessed via function.
In C# program Before you can start using the ODBC class definitions, you will need to include the right module. using System.Data.Odbc; // ODBC definitions.
Data Persistence in Android
CIS 270—App Dev II Big Java Chapter 22 Relational Databases.
SQLite Database. SQLite Public domain database – Advantages Small (about 150 KB) – Used on devices with limited resources Each database contained within.
Database Programming in Java Corresponds with Chapter 32, 33.
Content providers Accessing shared data in a uniform way 1Content providers.
Data Storage: Part 4 (Content Providers). Content Providers Content providers allow the sharing of data between applications. Inter-process communication.
COMP 365 Android Development.  Manages access from a central database  Allows multiple applications to access the same data.
Purdue Pride Joe Gutierrez Tung Ho Janam Jhaveri 4/7/2010Purdue Pride1.
Address Book App 1. Define styles   Specify a background for a TextView – res/drawable/textview_border.xml.
9 Persistence - SQLite CSNB544 Mobile Application Development Thanks to Utexas Austin.
Chapter 25 Databases. Chapter Scope Database concepts Tables and queries SQL statements Managing data in a database Java Foundations, 3rd Edition, Lewis/DePasquale/Chase25.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 31.1 Reviewing the Bookstore Application 31.2.
Creating competitive advantage Copyright © 2003 Enterprise Java Beans Presenter: Wickramanayake HMKSK Version:0.1 Last Updated:
SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.
Persistence Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5 License.
SQLite (part deux) 1 CS440. Traditional Model View Controller (MVC) CS440 2.
Mobile Software Development ISCG 7424 Department of Computing UNITEC John Casey and Richard Rabeder SQLite and Permissions.
Database UpdatestMyn1 Database Updates SQL is a complete data manipulation language that can be used for modifying the data in the database as well as.
Presentation On How To Create Connection To A Database.
CSCI 6962: Server-side Design and Programming JSF DataTables and Shopping Carts.
Video Games list lab 6  At the end of this lab you will be expected to know:  What Views, View Groups, Layouts, and Widgets are and how they relate to.
Oracle11g: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks.
SQLite DB Storing Data in Android RAVI GAURAV PANDEY 1.
Android - SQLite Database 12/10/2015. Introduction SQLite is a opensource SQL database that stores data to a text file on a device. Android comes in with.
SQlite. SQLite is a opensource SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation.
1. Playing with SQLite Database  SQLite : Database specific name for Android Application  For windows there are several kind of database name : Mysql,
Working With Database Library And Helpers. Connecting to your Database First you need to set parameters in you database.php file residing in config folder.
Jennifer Widom Relational Databases The Relational Model.
1 JDBC – Java Database Connectivity CS , Spring 2010.
Address Book App 1 Fall 2014 CS7020: Game Design and Development.
By: Eliav Menachi.  On Android, all application data (including files) are private to that application  Android provides a standard way for an application.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Data Storage in Android Димитър Н. Димитров. Why talk about data? Why not 3D graphics or network connectivity? Data as fundamental term in computer science.
Content Providers.
CS499 – Mobile Application Development
Making content providers
Content provider.
Database Access with SQL
Cosc 5/4730 Sqlite primer.
CS SQL.
Android Content Providers & SQLite
SQL – Python and Databases
ListView: Part 2.
Mobile Applications (Android Programming)
Android Application SQLite 1.
Android Database using SQLite
Mobile Application Development Chapter 5 [Persistent Data in Android]
Content Providers.
Lecture 8: Database Topics: Basic SQLite Operations.
Mobile Computing With Android ACST Android Database Storage Part 2
Relational Databases The Relational Model.
Relational Databases The Relational Model.
CMPE419 Mobile Application Development
CMPE419 Mobile Application Development
Mobile Computing With Android ACST 4550 Android Database Storage
Android Developer Fundamentals V2
Updating Databases With Open SQL
Department of School of Computing and Engineering
SQLLite and Android.
Lecture 8: Database Topics: Basic SQLite Operations.
Presentation transcript:

Database Programming Code Dissection

Layered Approach Presentation (Activity) DbSampleActivity.java DataAccess (DataSource) CommentsDataSource.java MySQLiteHelper.java Object Class (Entity) Comment.java

Activity (onCreate) public void onCreate() { instantiate and open datasource setupViews addButtonListener updateTable }

Activity (setupViews) dataTable = (TableLayout)findViewById(R.id.data_table); txtcomment = (EditText)findViewById(R.id.txtComment); txtauthor = (EditText)findViewById(R.id.txtAuthor); txtdelauthor = (EditText)findViewById(R.id.txtDelAuthor); btnadd = (Button)findViewById(R.id.btnAdd); btndelete = (Button)findViewById(R.id.btnDelete);

Activity (addButtonListener) btnadd.setOnClickListener(this); btndelete.setOnClickListener(this);

Activity (updateTable) while (dataTable.getChildCount() > 1) { dataTable.removeViewAt(1); } ArrayList > data = datasource.getAllRowsAsArrays(); for (int position=0; position < data.size(); position++) { TableRow tableRow= new TableRow(this); ArrayList row = data.get(position); TextView txtcomment = new TextView(this); txtcomment.setText(row.get(0).toString()); tableRow.addView(txtcomment); TextView txtauthor = new TextView(this); txtauthor.setText(row.get(1).toString()); tableRow.addView(txtauthor); dataTable.addView(tableRow); }

Activity (updateTable) while table has rows { remove first row } place data into an ArrayList ***ArrayList of ArrayList Objects*** loop based on the number of rows of data { instantiate a new TableRow Layout place the data of the current row into an ArrayList Object assign the row values into TextViews add the TextViews into the TableRow add the view to the display screen }

Activity (onClick) public void onClick(View view) { If add then datasource.createComment(fields); updateTable(); If delete then datasource.deleteComment(field); updateTable(); }

DataSource(createComment) public void createComment(String comment, String author) { ContentValues values = new ContentValues(); values.put(MySQLiteHelper.COLUMN_COMMENT, comment); values.put(MySQLiteHelper.COLUMN_AUTHOR, author); try { database.insert(MySQLiteHelper.TABLE_COMMENTS, null, values); } catch(Exception e) { Log.e("DB ERROR", e.toString()); e.printStackTrace(); }

DataSource(createComment) ContentValues used to insert new rows into tables each Content Value object represents a single table row as a map of column names to values

DataSource (getAllRowsAsArrays) public ArrayList > getAllRowsAsArrays() { ArrayList > dataArrays = new ArrayList >(); Cursor cursor; try { cursor = database.query(MySQLiteHelper.TABLE_COMMENTS, new String[]{MySQLiteHelper.COLUMN_COMMENT, MySQLiteHelper.COLUMN_AUTHOR}, null, null, null, null, null); cursor.moveToFirst(); if (!cursor.isAfterLast()) { do { ArrayList dataList = new ArrayList (); dataList.add(cursor.getString(0)); dataList.add(cursor.getString(1)); dataArrays.add(dataList); } while (cursor.moveToNext());} } catch (SQLException e) { Log.e("DB Error", e.toString()); e.printStackTrace(); } return dataArrays; }

DataSource (getAllRowsAsArrays) Cursors Queries in Android are returned as Cursor objects pointers to the result set within the underlying data provide a managed way of controlling your position (row) in the result set of a database query

SQLite Helper Class Database Schema database description declaration of table name and fields

SQLite Helper Class SQL SELECT INSERT UPDATE DELETE