1 / 13

Example – a list of contacts

Example – a list of contacts. See Contact.java at http://www.aber.ac.uk/~dcswww/Dept/Teaching/CourseNotes/current/CS12230/codeExamples/0-simple-examples/Contact.java What if we want the contacts data to persist?. Contact – OO model. UML class diagram Attributes name and phone

melosa
Download Presentation

Example – a list of contacts

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Example – a list of contacts • See Contact.java at • http://www.aber.ac.uk/~dcswww/Dept/Teaching/CourseNotes/current/CS12230/codeExamples/0-simple-examples/Contact.java • What if we want the contacts data to persist?

  2. Contact – OO model • UML class diagram • Attributes name and phone • Operation toString()

  3. Contact – ER model • Just the attributes • No operations • Still a UML class diagram

  4. Key-value pairs • Name is the key • Phone is the value • Data model is a kind of persistent hash table

  5. Storage choices • Text file • Spreadsheet • Browser • Database • Relational • Object oriented • NoSQL • Native XML • …

  6. Browser • HTML5 localStorage • localStorage.setItem(key, value) • localStorage.getItem(key) • For offline use, use appcache • Benefits • Limitations • Example

  7. SQLite • Create the SQLite database • http://www.sqlite.org/ • Use a shell tool – a convenient way to create the database in the first place • Or write a program

  8. Applications Programming with SQL/CLI • Obtain a handle on the database • Send SQL queries to the database management system using query functions • Process the results of those queries • Results are tables and must be transformed into types that the application program can use

  9. Java JDBCimage from http://www.cse.unsw.edu.au/~jas/talks/jdbc/notes.htmlaccessed 15/Oct/2012

  10. Java JDBC • Driver manager provides implementations of Connection, Statement and ResultSet • Connection acts as database handle • Statement enables creation and execution of SQL queries • ResultSet maintains a cursor that enables access to current row of data returned by query

  11. SQLite with Java JDBC • Suppose you have a database and a jdbc driver • In your Java program • Initialize the jdbcdriver Class.forName("org.sqlite.JDBC");causes org.sqlite.JDBC to be loaded at runtime • Get a connection this.connection= DriverManager.getConnection("jdbc:sqlite:"+dbname); • Use the connection to send SQL queries to the database • Contacts example

  12. Java Persistence API • Alternative to call level interface • Work directly with the object oriented data model • We’ll revisit this later in the course

  13. Summary • First think about • Where the data comes from • Why the data is stored • How it is to be used • Then think about • Data models • Data storage options • Applications programming

More Related