Services. Relational. Databases & JDBC. Today. Relational. Databases SQL JDBC. Next Time. Services. Relational. Databases & JDBC. Today.

Similar documents
COSC344 Database Theory and Applications. Java and SQL. Lecture 12

Using SQL Server Management Studio

Using DOTS as Apache Derby System Test

Why Is This Important? Database Application Development. SQL in Application Code. Overview. SQL in Application Code (Contd.

Database Migration from MySQL to RDM Server

Chapter 9 Java and SQL. Wang Yang wyang@njnet.edu.cn

A Brief Introduction to MySQL

How To Create A Table In Sql (Ahem)

CS/CE 2336 Computer Science II

Information Technology NVEQ Level 2 Class X IT207-NQ2012-Database Development (Basic) Student s Handbook

CS 377 Database Systems SQL Programming. Li Xiong Department of Mathematics and Computer Science Emory University

JDBC (Java / SQL Programming) CS 377: Database Systems

CS2506 Operating Systems II Lab 8, 8 th Tue/03 /2011 Java API

MS ACCESS DATABASE DATA TYPES

SQL. Short introduction

Supplement IV.D: Tutorial for MS Access. For Introduction to Java Programming By Y. Daniel Liang

DEVELOPING MULTITHREADED DATABASE APPLICATION USING JAVA TOOLS AND ORACLE DATABASE MANAGEMENT SYSTEM IN INTRANET ENVIRONMENT

Microsoft SQL Server Connector for Apache Hadoop Version 1.0. User Guide

HyperSQL User Guide. HyperSQL Database Engine (HSQLDB) 2.1. Edited by The HSQL Development Group, Blaine Simpson, and Fred Toussi

Fact Sheet In-Memory Analysis

4 Logical Design : RDM Schema Definition with SQL / DDL

SQL and Java. Database Systems Lecture 19 Natasha Alechina

SQL Server An Overview

Java 7 Recipes. Freddy Guime. vk» (,\['«** g!p#« Carl Dea. Josh Juneau. John O'Conner

Spring,2015. Apache Hive BY NATIA MAMAIASHVILI, LASHA AMASHUKELI & ALEKO CHAKHVASHVILI SUPERVAIZOR: PROF. NODAR MOMTSELIDZE

Systems Infrastructure for Data Science. Web Science Group Uni Freiburg WS 2012/13

sqlite driver manual

database abstraction layer database abstraction layers in PHP Lukas Smith BackendMedia

Porting from Oracle to PostgreSQL

Linas Virbalas Continuent, Inc.

IT2305 Database Systems I (Compulsory)

The release notes provide details of enhancements and features in Cloudera ODBC Driver for Impala , as well as the version history.

Course Objectives. Database Applications. External applications. Course Objectives Interfacing. Mixing two worlds. Two approaches

CSC 443 Data Base Management Systems. Basic SQL

CS346: Database Programming.

Using Netbeans and the Derby Database for Projects Contents

IT2304: Database Systems 1 (DBS 1)

Java DataBase Connectivity (JDBC)

MYSQL DATABASE ACCESS WITH PHP

Overview of Databases On MacOS. Karl Kuehn Automation Engineer RethinkDB

ODBC Client Driver Help Kepware, Inc.

A list of data types appears at the bottom of this document. String datetimestamp = new java.sql.timestamp(system.currenttimemillis()).

Microsoft SQL connection to Sysmac NJ Quick Start Guide

Supplement IV.C: Tutorial for Oracle. For Introduction to Java Programming By Y. Daniel Liang

Chapter 6: Physical Database Design and Performance. Database Development Process. Physical Design Process. Physical Database Design

CSE 530A Database Management Systems. Introduction. Washington University Fall 2013

Performance Tuning for the JDBC TM API

COSC 6397 Big Data Analytics. 2 nd homework assignment Pig and Hive. Edgar Gabriel Spring 2015

The JAVA Way: JDBC and SQLJ

SQL Server Table Design - Best Practices

Database Programming. Week *Some of the slides in this lecture are created by Prof. Ian Horrocks from University of Oxford

Raima Database Manager Version 14.0 In-memory Database Engine

Black Hat Briefings USA 2004 Cameron Hotchkies

Extracting META information from Interbase/Firebird SQL (INFORMATION_SCHEMA)

4 Simple Database Features

BCA. Database Management System

Package sjdbc. R topics documented: February 20, 2015

Apache Cassandra Query Language (CQL)

Database Access Through Java Technologies

Cloud Powered Mobile Apps with Azure

Database Extensions Visual Walkthrough. PowerSchool Student Information System

Chapter 1 JDBC: Databases The Java Way! What Is The JDBC? The JDBC Structure ODBC s Part In The JDBC Summary

Comparing SQL and NOSQL databases

Microsoft SQL Server to Infobright Database Migration Guide

Java Application Developer Certificate Program Competencies

PHP Language Binding Guide For The Connection Cloud Web Services

A Fully Standards-Based Approach to Logging High-Throughput Distributed Real-Time Data. Leveraging the DDS and SQL Standards

ODBC Driver Version 4 Manual

not at all a manual simply a quick how-to-do guide

Facebook Twitter YouTube Google Plus Website

Evaluation. Copy. Evaluation Copy. Chapter 7: Using JDBC with Spring. 1) A Simpler Approach ) The JdbcTemplate. Class...

Spectrum Technology Platform. Version 9.0. Enterprise Data Integration Guide

Geodatabase Programming with SQL

Title. Syntax. stata.com. odbc Load, write, or view data from ODBC sources. List ODBC sources to which Stata can connect odbc list

Financial Data Access with SQL, Excel & VBA

An Oracle White Paper August, Oracle JDBC Memory Management

SQL Server Array Library László Dobos, Alexander S. Szalay

Firebird. Embedded SQL Guide for RM/Cobol

Database Query 1: SQL Basics

SQL DATA DEFINITION: KEY CONSTRAINTS. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 7

Complex Data and Object-Oriented. Databases

Ontrack PowerControls V8.1 for SQL ReadMe

Once the schema has been designed, it can be implemented in the RDBMS.

Erlang ODBC Copyright Ericsson AB. All Rights Reserved. Erlang ODBC December 15, 2015

Database Access from a Programming Language: Database Access from a Programming Language

Database Access from a Programming Language:

Comparison of Open Source RDBMS

An Oracle White Paper June Migrating Applications and Databases with Oracle Database 12c

Hadoop Integration Guide

LSINF1124 Projet de programmation

SAP HANA SQLScript Reference

CSCI110 Exercise 4: Database - MySQL

EDI Process Specification

Architecting the Future of Big Data

ODBC Applications: Writing Good Code

Choosing a Data Model for Your Database

In This Lecture. SQL Data Definition SQL SQL. Notes. Non-Procedural Programming. Database Systems Lecture 5 Natasha Alechina

Transcription:

& & 1 & 2 Lecture #7 2008 3 Terminology Structure & & Database server software referred to as Database Management Systems (DBMS) Database schemas describe database structure Data ordered in tables, rows and columns Tables (relations) provide groupings of data Rows (tuples) contain data records Columns (attributes) provide field structure Keys are used for ids and references Data stored in rows (aka records, tuples) Data accessed and manipulated via, etc can store vast amounts of data also contains simple functions Creation of custom functions (stored procedures) supported by most major database systems Motivation Database Table & & Allows data storage to be structured after data access patterns Data can be indexed and hashed in memory - quick access A simple and expressive model that supports logic reasoning (first-order predicate logic) Simple and efficient data storage Database models support role-based development id username birthdate email 1 test1 1970-01-01 test1@jsp.com 2 test2 1970-01-02 test2@jsp.com 3 test3 1970-01-03 test3@jsp.com 4 test4 1970-01-04 test4@jsp.com 5 test5 1970-01-05 test5@jsp.com

Transactions Structured Query Language () & A way to provide safe concurrent access to databases Allows for several operations to be viewed as a single, atomic operation If an error occurs, all changes are undone (rollback) & Text-based language used to access databases Standardized versions exists (ANSI ) Most database vendors provide their own dialects Select queries are used to ask questions about data Insert, update and delete statements are used to manipulate databases Create, alter & drop statements are used to create, modify and destroy databases Most databases provide functions which can be called using Queries Queries & SELECT * FROM profile WHERE profile.id = 123 SELECT username, birthdate, email FROM profile WHERE profile.id = 123 & SELECT COUNT(*) FROM profile WHERE LEN(profile.email) > 0 SELECT * FROM user, profile WHERE user.id = profile.id AND LEN(profile.email) > 0 ORDER BY profile.username LIMIT 25 <- My dialect & Updates & Java Database Connectivity () INSERT INTO profile (id, username, birthdate, email) VALUES (123, test1, 1970-01-01, test1@jsp.com ) UPDATE profile SET email = test1@jsp.com WHERE id = 123 Java API for database access Constructed around a Driver Manager Database vendors provide drivers DELETE FROM profile WHERE id = 123 Aims to virtualize Java database access Switch database without changes in Java code

Data Types & & type BIT TINYINT SMALLINT INTEGER BIGINT FLOAT, DOUBLE BINARY, VARBINARY, LONGVARBINARY CHAR, VARCHAR, LONGVARCHAR NUMERIC, DECIMAL Java type boolean byte short int long double byte[] String BigDecimal Data Types Using & & type DATE TIME, TIMESTAMP CLOB BLOB ARRAY DISTINCT STRUCT REF JAVA OBJECT Java type java.sql.date java.sql.timestamp Clob Blob Array mapping underlying type Struct Ref underlying Java class 1 Load driver 2 Create database URL 3 Connect to database 4 Create a statement 5 Execute a query / update 6 Process results 7 Close connection Drivers Driver Example & & Data buffering Connection pooling Links to stored procedures Driver instantiated via dynamic class loading (required, need only be done once) public static void instantiatedriver (String driver) throws ClassNotFoundException try Class.forName(driver).newInstance(); catch (InstantiationException e) throw new ClassNotFoundException(e.getMessage()); catch (IllegalAccessException e) throw new ClassNotFoundException(e.getMessage());

Driver Example Database URLs & & static // Apache Derby instantiatedriver("org.apache.derby.jdbc.embeddeddriver"); // My instantiatedriver("com.mysql.jdbc.driver"); // Postgre instantiatedriver("org.postgresql.driver"); jdbc:dbms:[//host:port/]database Provides database connection information Contains host, port, database (optionally username/password) Database URL Examples Database Connections & & DBMS Apache Derby My Postgre URL jdbc:derby:database jdbc:mysql://host:3306/database jdbc:postgresql://host:5432/database Represents a connection to a database May result in an underlying TCP/IP connection Connection may be compressed / encrypted Costly to create, reuse is recommended Statement Types Statements & & Statement - simple statement PreparedStatement - precompiled statement CallableStatement - database stored procedure is constructed and parsed for each request Quick and easy Should be replace with prepared statements (when optimizing)

PreparedStatements CallableStatements & & Used to precompile a statement Parameters are added to the statement More efficient when queries are repeated Used to call stored procedures in a database Parameters are added to call Stored procedure executes in the DBMS More efficient than prepared statements Requires a stored procedure Ties the application to a particular DBMS ResultSets Select & & Interfaces to statement results Can be thought of as table views Doesn t actually contain all data returned from queries (requests data as needed) Can be used to both read and write data Exact behavior of ResultSets depends on statement type Retrieves data from the database ResultSet.CONCUR_READ_ONLY); String sql = "SELECT * FROM profile"; ResultSet resultset = statement.executequery(sql); resultset.next(); String id = resultset.getstring("id"); String username = resultset.getstring("username"); String birthdate = resultset.getstring("birthdate"); String email = resultset.getstring("email"); Insert ResultSet Insert & Inserts data into the database Data must be manually filtered / escaped ResultSet.CONCUR_UPDATABLE); String sql = "INSERT INTO profile (id, username, birthdate, email) " + "VALUES (123, test1, 1970-01-01, test1@jsp.com )"; ResultSet resultset = statement.execute(sql); & Inserts data into the database Data is filtered / escaped by ResultSet.CONCUR_UPDATABLE); String sql = "SELECT * FROM profile"; ResultSet resultset = statement.executequery(sql); resultset.movetoinsertrow(); resultset.updatestring("id","123"); resultset.updatestring("username","test1"); resultset.updatestring("birthdate","1970-01-01"); resultset.updatestring("email","test1@jsp.com"); resultset.insertrow();

ResultSet Update Transactions & & Updates existing data in the database Data is filtered / escaped by ResultSet.CONCUR_UPDATABLE); String sql = "SELECT * FROM profile WHERE id= 123 "; ResultSet resultset = statement.executequery(sql); resultset.next(); resultset.updatestring("username","test1"); resultset.updatestring("birthdate","1970-01-01"); resultset.updatestring("email","test1@jsp.com"); resultset.updaterow(); connection.setautocommit(false) (default: true) connection.commit() connection.rollback() Transaction Example MetaData & null; try connection = getconnection(); connection.setautocommit(false); runsomequery(); runanotherquery(); connection.commit(); catch (Exception e) connection.rollback(); finally try if (connection!= null) connection.close(); catch (Exception e) & Provides information about databases and drivers Commonly used to list tables, columns etc Comparable to introspection / Java reflection & Security