Lecture 10: Database Connectivity

Total Page:16

File Type:pdf, Size:1020Kb

Lecture 10: Database Connectivity Outline Persistence via Database Lecture 10: JDBC (Java Database Connectivity) Database Connectivity JDBC API -JDBC Wendy Liu CSC309F – Fall 2007 1 2 Java Persistence JDBC (Java Database Relational Database Connectivity) Management System Object relational (RDBMS) Persistence via Database mapping Object-oriented Java Data Object Database Management (JDO) System (OODBMS) Enterprise JavaBean (EJB) 3 4 Three Tier Architecture Database Advantages Data Safety data is immune to program crashes Concurrent Access atomic updates via transactions Fault Tolerance replicated DBs for instant fail-over on machine/disk crashes Data Integrity aids to keep data meaningful Scalability Database can handle small/large quantities of data in a uniform manner A way of saving and accessing structured data on Reporting persistent (disk) storage easy to write SQL programs to generate arbitrary reports 5 6 1 Relational Database Movie Database Example First published by Edgar F. Codd in 1970 A relational database consists of a collection showtimes of tables showtimeid movieid theaterid sdate stime available 1 1 1 3/20/2005 20:00:00 90 A table consists of rows and columns 2 1 1 3/20/2005 22:00:00 90 orders Each row represents a record orderid userid showtimeid 11 1 Each column represents an attribute of the records contained in the table 7 8 RDBMS Technology Client/Server Databases Derby, Oracle, Sybase, MySQL, PointBase, SQLServer JDBC Embedded Databases (Java DataBase Connectivity) Derby,PointBase Personal Databases Access 9 10 JDBC Background JDBC Architecture Common SQL database access interface Allow Java programs to issue SQL statements and process the results Database independence Can update underlying database with minimal code impact Represent database constructs as objects Database connections, SQL statements, result sets, and database metadata http://java.sun.com/docs/books/tutorial/jdbc/basics/index.html 11 12 2 Components of JDBC Architecture - 1 Components of JDBC Architecture - 2 Java application JDBC Driver In need to access database Translates API calls to requests made against the Uses the API specific database JDBC API Specific driver required for the chosen database Installed on the client. Usually a set of class files Provides DB independent abstraction to placed in the class path Establish a connection with a database Send SQL statements All large databases are now supported Process the results 13 14 Components of JDBC Architecture - 3 DBMS The actual database engine Derby, MySQL, Oracle, SQL Server, MS Access, PointBase, Postgresql JDBC API v3.0 v4.0 (May incur different class names in the Derby drivers) 15 16 API Highlights Establishing a Connection http://java.sun.com/javase/6/docs/api/ javax.sql javax.sql DataSource getConnection() DataSource java.sql - Read the full method signatures from this API carefully before using - public Connection getConnection() Connection commit(), rollback(), setAutoCommit() Attempts to establish a connection with the data source For transactions that this DataSource object represents createStatement(), prepareStatement() For SQL statements public Connection getConnection(String username, Statement executeQuery(), executeUpdate() String password) PreparedStatement Precompiled SQL statement; more efficient for multiple executions Attempts to establish a connection with the data source executeQuery(), executeUpdate(), setInt(), setString() that this DataSource object represents using the given Parameter index starts from 1 ResultSet username and password next() Accessing next row getString(), getInt() Retrieving attribute values 17 18 3 Derby Example 1: Connection Executing a Query import org.apache.derby.jdbc.EmbeddedDataSource; java.sql import javax.sql.DataSource; PreparedStatement import java.sql.*; Precompiled SQL statement; more efficient for multiple executions … executeQuery(), executeUpdate(), setInt(), setString() // Driver code Parameter index starts from 1 EmbeddedDataSource eds = new EmbeddedDataSource(); Statement eds.setDatabaseName(dbname); executeQuery(), executeUpdate() eds.setCreateDatabase("create"); ResultSet … next() // JDBC code Accessing next row Connection con = eds.getConnection(); getString(), getInt() Retrieving attribute values 19 20 Example: PreparedStatement Example: Executing Query String insertStmt="INSERT INTO ACCOUNT Statement stmt = con.createStatement(); (NAME, AMOUNT) VALUES (?, ?);"; PreparedStatement ps = con.prepareStatement(insertStmt); // Send the query to the DB, get back a ResultSet ResultSet rs = stmt.executeQuery("SELECT * FROM PART;"); // Fill in the first and second args // Go through all rows returned by the query ps.setString(1,"Charlie Smith"); while(rs.next()){ ps.setDouble(2, 23.45); // Pull out individual columns from the current row int rowsAffected = ps.executeUpdate(); int pno = rs.getInt("PNO"); String pname = rs.getString("PNAME"); // Replace the first and second args // Print out the values ps.setString(1, "Arnold Jones"); System.out.println(pno + "\t“ + pname); ps.setDouble(2, 102.23); } rowsAffected=ps.executeUpdate(); rs.close(); 21 22 Executing Update int rowsAffected = stmt.executeUpdate( "DELETE * FROM ACCOUNTS;"); Executes SQL INSERT, UPDATE, or Announcements DELETE statements Returns the number of rows affected 23 24 4 Midterm Important Announcement (Repeat) Topics covered Tuesday Oct 16, 2007 Lectures 1-9 inclusive 2-hr tutorial given in a CDF lab, BA3185 From XHTML to Java Servlets and JSP Thursday Oct 18, 2007 Use lecture notes as a guideline Midterm, BA2195 You can bring only 1 page cheat-sheet Starting Tuesday Oct 23, 2007 Letter size Double sided The official lecture room will be BA2185 on each Tuesday until the end of term Format similar to previous years No change to Thursdays’ classes (BA1240) Short conceptual questions ~40% Programming questions ~60% 25 26 5.
Recommended publications
  • Lesson 17 Building Xqueries in Xquery Editor View
    AquaLogic Data Services Platform™ Tutorial: Part II A Guide to Developing BEA AquaLogic Data Services Platform (DSP) Projects Note: This tutorial is based in large part on a guide originally developed for enterprises evaluating Data Services Platform for specific requirements. In some cases illustrations, directories, and paths reference Liquid Data, the previous name of the Data Services Platform. Version: 2.1 Document Date: June 2005 Revised: June 2006 Copyright Copyright © 2005, 2006 BEA Systems, Inc. All Rights Reserved. Restricted Rights Legend This software and documentation is subject to and made available only pursuant to the terms of the BEA Systems License Agreement and may be used or copied only in accordance with the terms of that agreement. It is against the law to copy the software except as specifically allowed in the agreement. This document may not, in whole or in part, be copied photocopied, reproduced, translated, or reduced to any electronic medium or machine readable form without prior consent, in writing, from BEA Systems, Inc. Use, duplication or disclosure by the U.S. Government is subject to restrictions set forth in the BEA Systems License Agreement and in subparagraph (c)(1) of the Commercial Computer Software- Restricted Rights Clause at FAR 52.227-19; subparagraph (c)(1)(ii) of the Rights in Technical Data and Computer Software clause at DFARS 252.227-7013, subparagraph (d) of the Commercial Computer Software--Licensing clause at NASA FAR supplement 16-52.227-86; or their equivalent. Information in this document is subject to change without notice and does not represent a commitment on the part of BEA Systems.
    [Show full text]
  • Rdbmss Why Use an RDBMS
    RDBMSs • Relational Database Management Systems • A way of saving and accessing data on persistent (disk) storage. 51 - RDBMS CSC309 1 Why Use an RDBMS • Data Safety – data is immune to program crashes • Concurrent Access – atomic updates via transactions • Fault Tolerance – replicated dbs for instant failover on machine/disk crashes • Data Integrity – aids to keep data meaningful •Scalability – can handle small/large quantities of data in a uniform manner •Reporting – easy to write SQL programs to generate arbitrary reports 51 - RDBMS CSC309 2 1 Relational Model • First published by E.F. Codd in 1970 • A relational database consists of a collection of tables • A table consists of rows and columns • each row represents a record • each column represents an attribute of the records contained in the table 51 - RDBMS CSC309 3 RDBMS Technology • Client/Server Databases – Oracle, Sybase, MySQL, SQLServer • Personal Databases – Access • Embedded Databases –Pointbase 51 - RDBMS CSC309 4 2 Client/Server Databases client client client processes tcp/ip connections Server disk i/o server process 51 - RDBMS CSC309 5 Inside the Client Process client API application code tcp/ip db library connection to server 51 - RDBMS CSC309 6 3 Pointbase client API application code Pointbase lib. local file system 51 - RDBMS CSC309 7 Microsoft Access Access app Microsoft JET SQL DLL local file system 51 - RDBMS CSC309 8 4 APIs to RDBMSs • All are very similar • A collection of routines designed to – produce and send to the db engine an SQL statement • an original
    [Show full text]
  • Eclipselink Understanding Eclipselink 2.4
    EclipseLink Understanding EclipseLink 2.4 June 2013 EclipseLink Concepts Guide Copyright © 2012, 2013, by The Eclipse Foundation under the Eclipse Public License (EPL) http://www.eclipse.org/org/documents/epl-v10.php The initial contribution of this content was based on work copyrighted by Oracle and was submitted with permission. Print date: July 9, 2013 Contents Preface ............................................................................................................................................................... xiii Audience..................................................................................................................................................... xiii Related Documents ................................................................................................................................... xiii Conventions ............................................................................................................................................... xiii 1 Overview of EclipseLink 1.1 Understanding EclipseLink....................................................................................................... 1-1 1.1.1 What Is the Object-Persistence Impedance Mismatch?.................................................. 1-3 1.1.2 The EclipseLink Solution.................................................................................................... 1-3 1.2 Key Features ...............................................................................................................................
    [Show full text]
  • Java Database Technologies (Part I)
    Extreme Java G22.3033-007 Session 12 - Main Theme Java Database Technologies (Part I) Dr. Jean-Claude Franchitti New York University Computer Science Department Courant Institute of Mathematical Sciences 1 Agenda Summary of Previous Session Applications of Java to Database Technology Database Technology Review Basic and Advanced JDBC Features J2EE Enterprise Data Enabling XML and Database Technology Readings Class Project & Assignment #5a 2 1 Summary of Previous Session Summary of Previous Session Enterprise JavaBeans (EJBs) J2EE Connector Architecture Practical Survey of Mainstream J2EE App. Servers Web Services Developer Pack Enterprise Application Integration (EAI) and Business to Business Integration (B2Bi) J2EE Blueprint Programs Class Project & Assignment #4c 3 Part I Java and Database Technology Also See Session 12 Handout on: “Java and Database Technology (JDBC)” and Session 12 Presentation on: “Designing Databases for eBusiness Solutions” 4 2 Review of Database Technology Introduction to Database Technology Data Modeling Conceptual Database Design Logical Database Design Physical Database Design Database System Programming Models Database Architectures Database Storage Management Database System Administration Commercial Systems: www.oracle.com,www.ibm.com/db2, http://www- 3.ibm.com/software/data/informix/,www.sybase.com 5 Advanced Database Concepts Parallel and Distributed Databases Web Databases Data Warehousing and Data Mining Mobile Databases Spatial and Multimedia Databases Geographic Information
    [Show full text]
  • Embedded Database for Remote Process Management System
    Embedded Database for Remote Process Management System {tag} {/tag} IJCA Proceedings on International Conference on Emerging Frontiers in Technology for Rural Area (EFITRA-2012) © 2012 by IJCA Journal EFITRA - Number 4 Year of Publication: 2012 Authors: Kalyani N. Satone Madhuri M . Pal {bibtex}efitra1030.bib{/bibtex} Abstract This paper investigates embedded databases for the MicroBaseJ project. The paper aims at the development of an integrated database and a user interface for a typical 3G mobile phone with Java MIDP2 capability. One of the key objectives is to target a generic solution. A number of commercial sectors could benefit from this solution such as horticulture, building management, pollution/water management, industry etc. Four embedded databases based on J2ME have been investigated. Two of the four have been evaluated and analyzed. The size of processed data is limited to 20000 records when using the wireless toolkit simulator and 11000 records when using a mobile phone. 1 / 3 Embedded Database for Remote Process Management System Refer ences - Mobile and World, "Subscriber statistics end Q1 2007," 2007. - S. Ravi, M. Chathish, and H. Prasanna, "WAP AND SMS BASED EMERGING TECHNIQUES FOR REMOTEMONITORING AND CONTROL OF A PROCESS PLANT," in ICSP'04. 2004 7th International Conference, 2004, pp. 2672-2675. - K. Hung and Y. Zhang, "Implementation of a WAP-Based Telemedicine System for Patient Monitoring," Information Technology in Biomedicine, vol. IEEE Transations on vol. 7, pp. 101-107, June 2003. - M. Nikolova, F. Meijs, and P. Voorwinden, "Remote Mobile Control of Home appliances," Consumer Electronis, vol.
    [Show full text]
  • Dynamic Information with IBM Infosphere Data Replication CDC
    Front cover IBM® Information Management Software Smarter Business Dynamic Information with IBM InfoSphere Data Replication CDC Log-based for real-time high volume replication and scalability High throughput replication with integrity and consistency Programming-free data integration Chuck Ballard Alec Beaton Mark Ketchie Anzar Noor Frank Ketelaars Judy Parkes Deepak Rangarao Bill Shubin Wim Van Tichelen ibm.com/redbooks International Technical Support Organization Smarter Business: Dynamic Information with IBM InfoSphere Data Replication CDC March 2012 SG24-7941-00 Note: Before using this information and the product it supports, read the information in “Notices” on page ix. First Edition (March 2012) This edition applies to Version 6.5 of IBM InfoSphere Change Data Capture (product number 5724-U70). © Copyright International Business Machines Corporation 2012. All rights reserved. Note to U.S. Government Users Restricted Rights -- Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents Notices . ix Trademarks . x Preface . xi The team who wrote this book . xii Now you can become a published author, too! . xvi Comments welcome. xvii Stay connected to IBM Redbooks . xvii Chapter 1. Introduction and overview . 1 1.1 Optimized data integration . 2 1.2 InfoSphere architecture . 4 Chapter 2. InfoSphere CDC: Empowering information management. 9 2.1 The need for dynamic data . 10 2.2 Data delivery methods. 11 2.3 Providing dynamic data with InfoSphere CDC . 12 2.3.1 InfoSphere CDC architectural overview . 14 2.3.2 Reliability and integrity . 16 Chapter 3. Business use cases for InfoSphere CDC . 19 3.1 InfoSphere CDC techniques for transporting changed data .
    [Show full text]
  • Java Database Connectivity (JDBC) J2EE Application Model
    Java DataBase Connectivity (JDBC) J2EE application model J2EE is a multitiered distributed application model client machines the J2EE server machine the database or legacy machines at the back end JDBC API JDBC is an interface which allows Java code to execute SQL statements inside relational databases Java JDBC driver program connectivity for Oracle data processing utilities driver for MySQL jdbc-odbc ODBC bridge driver The JDBC-ODBC Bridge ODBC (Open Database Connectivity) is a Microsoft standard from the mid 1990’s. It is an API that allows C/C++ programs to execute SQL inside databases ODBC is supported by many products. The JDBC-ODBC Bridge (Contd.) The JDBC-ODBC bridge allows Java code to use the C/C++ interface of ODBC it means that JDBC can access many different database products The layers of translation (Java --> C --> SQL) can slow down execution. The JDBC-ODBC Bridge (Contd.) The JDBC-ODBC bridge comes free with the J2SE: called sun.jdbc.odbc.JdbcOdbcDriver The ODBC driver for Microsoft Access comes with MS Office so it is easy to connect Java and Access JDBC Pseudo Code All JDBC programs do the following: Step 1) load the JDBC driver Step 2) Specify the name and location of the database being used Step 3) Connect to the database with a Connection object Step 4) Execute a SQL query using a Statement object Step 5) Get the results in a ResultSet object Step 6) Finish by closing the ResultSet, Statement and Connection objects JDBC API in J2SE Set up a database server (Oracle , MySQL, pointbase) Get a JDBC driver
    [Show full text]
  • Investigating a Constraint-Based Approach to Data Quality in Information Systems
    Research Collection Master Thesis Investigating a Constraint-Based Approach to Data Quality in Information Systems Author(s): Probst, Oliver Publication Date: 2013 Permanent Link: https://doi.org/10.3929/ethz-a-009980065 Rights / License: In Copyright - Non-Commercial Use Permitted This page was generated automatically upon download from the ETH Zurich Research Collection. For more information please consult the Terms of use. ETH Library Investigating a Constraint-Based Approach to Data Quality in Information Systems Master Thesis Oliver Probst <[email protected]> Prof. Dr. Moira C. Norrie David Weber Global Information Systems Group Institute of Information Systems Department of Computer Science 8th October 2013 Copyright © 2013 Global Information Systems Group. ABSTRACT Constraints are tightly coupled with data validation and data quality. The author investigates in this master thesis to what extent constraints can be used to build a data quality manage- ment framework that can be used by an application developer to control the data quality of an information system. The conceptual background regarding the definition of data qual- ity and its multidimensional concept followed by a constraint type overview is presented in detail. Moreover, the results of a broad research for existing concepts and technical solu- tions regarding constraint definition and data validation with a strong focus on the JavaTM programming language environment are explained. Based on these insights, we introduce a data quality management framework implementation based on the JavaTM Specification Request (JSR) 349 (Bean Validation 1.1) using a single constraint model which avoids in- consistencies and redundancy within the constraint specification and validation process. This data quality management framework contains advanced constraints like an association con- straint which restricts the cardinalities between entities in a dynamic way and the concept of temporal constrains which allows that a constraint must only hold at a certain point in time.
    [Show full text]
  • Understanding Oracle Toplink
    Oracle® Fusion Middleware Understanding Oracle TopLink 12c (12.2.1.4.0) F16472-02 January 2020 Oracle Fusion Middleware Understanding Oracle TopLink, 12c (12.2.1.4.0) F16472-02 Copyright © 2014, 2020, Oracle and/or its affiliates. All rights reserved. This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is prohibited. The information contained herein is subject to change without notice and is not warranted to be error-free. If you find any errors, please report them to us in writing. If this is software or related documentation that is delivered to the U.S. Government or anyone licensing it on behalf of the U.S. Government, then the following notice is applicable: U.S. GOVERNMENT END USERS: Oracle programs, including any operating system, integrated software, any programs installed on the hardware, and/or documentation, delivered to U.S. Government end users are "commercial computer software" pursuant to the applicable Federal Acquisition Regulation and agency- specific supplemental regulations. As such, use, duplication, disclosure, modification, and adaptation of the programs, including any operating system, integrated software, any programs installed on the hardware, and/or documentation, shall be subject to license terms and license restrictions applicable to the programs.
    [Show full text]
  • Talend Open Studio for Data Quality User Guide
    Talend Open Studio for Data Quality User Guide 6.1.2 Talend Open Studio for Data Quality Adapted for v6.1.2. Supersedes previous releases. Publication date: September 13, 2016 Copyleft This documentation is provided under the terms of the Creative Commons Public License (CCPL). For more information about what you can and cannot do with this documentation in accordance with the CCPL, please read: http://creativecommons.org/licenses/by-nc-sa/2.0/ Notices Talend is a trademark of Talend, Inc. All brands, product names, company names, trademarks and service marks are the properties of their respective owners. License Agreement The software described in this documentation is licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.html. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. This product includes software developed at ASM, AntlR, Apache ActiveMQ, Apache Ant, Apache Axiom, Apache Axis, Apache Axis 2, Apache Chemistry, Apache Common Http Client, Apache Common Http Core, Apache Commons, Apache Commons Bcel, Apache Commons Lang, Apache Datafu, Apache Derby Database Engine and Embedded JDBC Driver, Apache Geronimo, Apache HCatalog,
    [Show full text]
  • Database Size Requirements for Schema
    Database Size Requirements For Schema Uncoordinated Jodie exscinds some Kaffir after breakneck Hewitt sought tamely. Angel twill stably. Combustion and interpenetrative Bjorn overcapitalized her extra phytologists brown-nose and incite thereto. When the search used to database size requirements for schema structure of more features that can also note that specifies that include billions of. To meet quick business requirements laid waste to handle although in market dynamics new. As soap a schema suggestion model for NoSQL databases is posed to. Note that TeamCity assumes ownership over your database schema. ADMINGETTABINFO table function retrieve table size. Spspaceused gives you the size of collide the indexes combined The results are usually slightly different theme within 1 On SQL 2012 getting this information on for table level but become deliciously simple SQL Management Studio Right arm on Db Reports Standard Reports Disk usage is table. SELECT stnamessname FROM systables st join sysschemas ss. The decision if building space needs to be deallocated depends on still other. Data Types Schema Types and Schema Evolution. How much life has been used by different objects in HANA database. Unpack the debezium connector offsets for database size schema? Command To Export Mysql Database Schema Tenzing. Writing each phase to exacerbate problems, size for database schema structure and cache and manipulating as. When database schema registry and the appropriate data on the orion platform streamlines data. Is the requirement to heaven all depart the tables memory requirements 'up-front' word too. Very Quciky filling DB schema size Dynatrace Answers. Use to guess, everything but it is used space required to the constraints are for schema? Typical bad effects of redundancy are an unnecessary increase customer database size data often prone to inconsistency and decreases in the efficiency of the.
    [Show full text]
  • Tool Support for Architectural Decision Making in Large Software Intensive Projects
    TECHNISCHE UNIVERSITÄT MÜNCHEN Lehrstuhl für Informatik XIX Tool support for architectural decision making in large software intensive projects Manoj Mahabaleshwar Vollständiger Abdruck der von der Fakultät für Informatik der Technischen Universität München zur Erlangung des akademischen Grades eines Doktors der Naturwissenschaften (Dr. rer. nat.) genehmigten Dissertation. Vorsitzender: Univ.-Prof. Dr. Alexander Pretschner Prüfer der Dissertation: 1. Univ.-Prof. Dr. Florian Matthes 2. Univ.-Prof. Dr. Bernd Brügge Die Dissertation wurde am 31.10.2019 bei der Technischen Universität München eingereicht und durch die Fakultät für Informatik am 08.03.2020 angenommen. II Zusammenfassung Während des letztens Jahrzehnts hat sich ein Paradigmenwechsel vollzogen, in der Weise, in der Wissenschaftler und Praktiker Softwarearchitekturen betrachten. Eine Softwarearchitektur wird heutzutage nicht nur als Blaupause gesehen, sondern als eine Menge von Designentscheidungen, die zur Blaupause des zugrundeliegenden Softwaresystems führen. Architekten und Entwick- ler treffen regelmäßig Designentscheidungen, die zum Beispiel die Wahl eines Architekturstils, eines Entwurfsmusters und der zugrundeliegenden IT-Infrastruktur betreffen. Die Dokumen- tation solcher Entscheidungen hilft, in großen Projekten, Fragen zu beantworten wie: „Welche Designentscheidungen wurden bereits getroffen?”, „Welche Architekturelemente und Qualität- sattribute werden von einer Entscheidung beeinflusst?”, „Wer sollte in eine neue Entscheidung involviert sein?”, „Welche ähnlichen
    [Show full text]