Departamento de Lenguajes y Sistemas Informáticos

Similar documents
PERSİSTENCE OBJECT RELATİON MAPPİNG

Cyrus Shahabi Computer Science Department University of Southern California C. Shahabi

Application Programming for Relational Databases

Diseño de la capa de datos para el POS

Part I: Stored Procedures. Introduction to SQL Programming Techniques. CSC 375, Fall 2017

JDBC Programming: Intro

JDBC, Transactions. Niklas Fors JDBC 1 / 38

13 Creation and Manipulation of Tables and Databases

Database Application Development

e-pg Pathshala Subject: Computer Science Paper: Web Technology Module: JDBC INTRODUCTION Module No: CS/WT/26 Quadrant 2 e-text

Discuss setting up JDBC connectivity. Demonstrate a JDBC program Discuss and demonstrate methods associated with JDBC connectivity

Java Database Connectivity (JDBC) 25.1 What is JDBC?

Preview from Notesale.co.uk Page 21 of 162

CSC System Development with Java. Database Connection. Department of Statistics and Computer Science. Budditha Hettige

Calling SQL from a host language (Java and Python) Kathleen Durant CS 3200

JDBC Overview. Java Database Connectivity. Gregg Lippa Senior Technical Analyst Themis Education Themis, Inc.

Topic 12: Database Programming using JDBC. Database & DBMS SQL JDBC

COP4540 TUTORIAL PROFESSOR: DR SHU-CHING CHEN TA: H S IN-YU HA

Enterprise Systems. Lecture 02: JDBC. Behzad BORDBAR

Database Programming Overview. COSC 304 Introduction to Database Systems. Database Programming. JDBC Interfaces. JDBC Overview

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer

Enterprise Java Unit 1- Chapter 6 Prof. Sujata Rizal

Lab # 9. Java to Database Connection

DataBase Lab JAVA-DATABASE CONNECTION. Eng. Haneen El-masry

JDBC Architecture. JDBC API: This provides the application-to- JDBC Manager connection.

Server-side Web Programming

BUSINESS INTELLIGENCE LABORATORY. Data Access: Relational Data Bases. Business Informatics Degree

Servlet 5.1 JDBC 5.2 JDBC

You write standard JDBC API application and plug in the appropriate JDBC driver for the database the you want to use. Java applet, app or servlets

JDBC Drivers Type. JDBC drivers implement the defined interfaces in the JDBC API for interacting with your database server.

CSCI/CMPE Object-Oriented Programming in Java JDBC. Dongchul Kim. Department of Computer Science University of Texas Rio Grande Valley

SQL in a Server Environment (ii)

Java Database Connectivity

Designing a Persistence Framework

Databases 2012 Embedded SQL

The Design of JDBC The Structured Query Language Basic JDBC Programming Concepts Query Execution Scrollable and Updatable Result Sets

SQL in a Server Environment

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

CSE 530A. DAOs and MVC. Washington University Fall 2012

This lecture. Databases - JDBC I. Application Programs. Database Access End Users

JDBC 3.0. Java Database Connectivity. 1 Java

Unit 2 JDBC Programming

Introduction to Databases

Outline. Lecture 10: Database Connectivity -JDBC. Java Persistence. Persistence via Database

Database Application Development Part 2 - Chapter

Introduction to JDBC. Lecture 12

DB Programming. Database Systems

Enterprise JavaBeans. Layer:08. Persistence

Overview. Database Application Development. SQL in Application Code. SQL in Application Code (cont.)

Database Application Development

Database Application Development

More Database Programming. CS157A Chris Pollett Nov. 2, 2005.

SQL and Java. Database Systems Lecture 20 Natasha Alechina

How to program applications. CS 2550 / Spring 2006 Principles of Database Systems. SQL is not enough. Roadmap

Working with Databases and Java

Introduction to JDBC. JDBC: Java Database Connectivity. Why Access a Database with Java? Compilation. Six Steps. Packages to Import

SQL DML and DB Applications, JDBC

Contents. Introducing the course. Aim: to learn engineering of multi-tired web based systems. Road map of the course. Roadmap..

Persistency Patterns. Repository and DAO

ERwin and JDBC. Mar. 6, 2007 Myoung Ho Kim

Questions and Answers. A. A DataSource is the basic service for managing a set of JDBC drivers.

Package. com.jpbc. Page 1 of 26

Databases and JDBC. by Vlad Costel Ungureanu for Learn Stuff

Lecture 2. Introduction to JDBC

Unit 3 - Java Data Base Connectivity

SQL: Programming. Announcements (September 25) Motivation. CPS 116 Introduction to Database Systems. Pros and cons of SQL.

UNIT-3 Java Database Client/Server

Java and the Java DataBase Connectivity (JDBC) API. Todd Kaufman April 25, 2002

Student Number: Please fill out the identification section above as well as the one on the back page, and read the instructions below. Good Luck!

Java application using JDBC to connect to a database.

The Data Tier of the Java EE Architecture

Oracle TimesTen In-Memory Database

Lecture 9&10 JDBC. Mechanism. Some Warnings. Notes. Style. Introductory Databases SSC Introduction to DataBases 1.

Oracle TimesTen In-Memory Database

CHAPTER 2 JDBC FUNDAMENTALS

Introduction to Databases [p.3]

Embedded SQL. csc343, Introduction to Databases Renée J. Miller and Fatemeh Nargesian and Sina Meraji Winter 2018

Databases and MySQL. COMP 342: Programming Methods. 16 September Databases and MySQL

Databases and SQL Lab EECS 448

SQL-PL Interface. Murali Mani. Perl /CGI with Oracle/mySQL Install your own web server and use servlets with JDBC and Oracle/mySQL

Three-Tier Architecture

MANTHLY TEST SEPTEMBER 2017 QUESTION BANK CLASS: XII SUBJECT: INFORMATICS PRACTICES (065)

Relational Databases. CS 240 Advanced Programming Concepts

O ne of the most important features of JavaServer

Intoduction to JDBC (Java Database Connectivity-- Connecting to DBMS)

INTRODUCTION TO JDBC - Revised Spring

Chapter 16: Databases

Database Applications (15-415)

Accessing databases in Java using JDBC

Instructor: Jinze Liu. Fall 2008

Visit for more.

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Information Science and Engineering

Database Access with JDBC. Dr. Jens Bennedsen, Aarhus University, School of Engineering Aarhus, Denmark

SQL: Programming Midterm in class next Thursday (October 5)

JAVA AND DATABASES. Summer 2018

( A ) 8. If the address of an array is stored in $value, how do you get the values of this array? (B) \$value (C) &$value (D) $$value

Chapter 10 Java and SQL. Wang Yang

Chapter 5: Advanced SQL" Chapter 5: Advanced SQL"

Embedded SQL. csc343, Introduction to Databases Diane Horton with examples from Ullman and Widom Fall 2014

IBM -

Transcription:

Departamento de Lenguajes y Sistemas Informáticos

! "

# $% &'' () * +,

! -. /,#0 &. +, +*,1 $23.*4.5*46.-.2) 7.,8 +*,1 $ 6 +*,1) $23.*4.5 7.-.2)

9

:$java.sql.*),,1 $ ;0,9,1<&) +, :$ )

" # $% $< ) 9 # &%# * # '% -==>., +, # (% -==>.? +,

) *

9 +,

+, 3 Driver dbdriver = (Driver) Class.forName(driverName).newInstance(); DriverManager.registerDriver(dBDriver); 3 DriverManager.deregisterDriver(dBDriver); ' 3 com.microsoft.jdbc.sqlserver.sqlserverdriver (,1, )@com.mysql.jdbc.driver (+*,1 )

9 -+.

), #A9 :+, jdbc:mysql://127.0.0.1:3306/pos 3jdbc 3mysql 0 3127.0.0.1 33306 3POS

-+. # * 3 Connection conn = DriverManager.getConnection(dBUri, username, password); 3 conn.close();

9 /0

/0

Statement,1 ; PreparedStatement,1@ $;;)* ; CallableStatement

PreparedStatement, B preparestatement PreparedStatement preparestatement(string s) '; s 2 :,1@ 4 ; String sql = "DELETE FROM Customer WHERE (CUSTOMERID =?)"; ; @B setxxx(x,y) $x : ; @y 4 )

)1 setxxx(x,y) )1 PreparedStatement setboolean(x,y) setbyte(x,y) setdate(x,y) setdouble(x,y) setfloat(x,y) setint(x,y) setlong(x,y) setstring(x,y) settime(x,y) settimestamp(x,y) setobject(x,y) #, y boolean byte Date double float int long String Time TimeStamp Object

2* PreparedStatement stmt = null; String sql = "DELETE FROM Customer WHERE (CUSTOMERID =? ) "; stmt = conn.preparestatement(sql); //conn es una conexión válida stmt.setstring(1, customerid); PreparedStatement stmt = null; String sql = "SELECT * FROM Customer"; stmt = conn.preparestatement(sql); //conn es una conexión válida PreparedStatement stmt = null; String sql = "INSERT INTO CUSTOMER (OID, CUSTOMERID, NAME, SURNAME) + VALUES (?,?,?,?)"; stmt = conn.preparestatement(sql); stmt.setstring(1, 33423 ); stmt.setstring(2, Customer 1 ); stmt.setstring(3, Name 1 ); stmt.setstring(4, Name 2 );

2*

)1 PreparedStatement ResultSet executequery() ' %,''(@ ResultSet int executeupdate() ' %90,'A(@ %#'( %'''(. C boolean execute() @D

#

# ','' ResulSet +B B3 next()3 : ResulSet $ : ) getxxx(s)3 @ :@ :s $E )

)1 getxxx(s) )1 3 getboolean(s) getbyte(s) getdate(s) getdouble(s) getfloat(s) getint(s) getlong(s) getstring(s) gettime(s) gettimestamp(s) getobject(s) #, boolean byte Date double float int long String Time TimeStamp Object

/

/ 3 PreparedStatement ResulSet $2,'') PreparedStatement stmt = null; ResulSet result = null;... stmt.close(); result.close();

2* <<Class Model>> <<Physical Data Model>>!"#!"!"

2* Select4$5 PreparedStatement stmt = null; ResultSet result = null; Customer c = null; String sql = "SELECT * FROM CUSTOMER WHERE (CUSTOMERID =? ) "; stmt = conn.preparestatement(sql); //conn es una conexión válida stmt.setstring(1, customerid); result = stmt.executequery(); result.next(); c = new Customer(); c.setcustomerid(result.getstring("customerid")); c.setname(result.getstring("name")); c.setsurname(result.getstring("surname")); result.close(); stmt.close();

2* Select4&5 PreparedStatement stmt = null; List searchresults = new LinkedList(); ResultSet result = null; String sql = "SELECT * FROM Customer"; stmt = conn.preparestatement(sql); //conn es una conexión válida stmt.executequery(); result = stmt.executequery(); while (result.next()) { Customer temp = new Customer(); temp.setcustomerid(result.getstring("customerid")); temp.setname(result.getstring("name")); temp.setsurname(result.getstring("surname")); searchresults.add(temp); } result.close(); stmt.close();

2* Insert PreparedStatement stmt = null; String oid = UIDGenerator.getInstance().getKey(); String sql = "INSERT INTO CUSTOMER (OID, CUSTOMERID, NAME, SURNAME) + VALUES (?,?,?,?)"; stmt = conn.preparestatement(sql); stmt.setstring(1, oid); stmt.setstring(2, c.getcustomerid()); stmt.setstring(3, c.getname()); stmt.setstring(4, c.getsurname()); stmt.executeupdate(); stmt.close();

2* Delete String sql = "DELETE FROM Customer WHERE (CUSTOMERID =? ) "; PreparedStatement stmt = null; stmt = conn.preparestatement(sql); //conn es una conexión válida stmt.setstring(1, customerid); stmt.executeupdate(); stmt.close();

9 #.

#., 3 (Class.forName): InstantiationException IllegalAccessException ClassNotFoundException B : : 4 $ )3 SQLException

., )1 *... try { // Aquí va el código para cargar el driver } catch(exception e) { System.err.println(e.getMessage()); }...... try { // Aquí va el código que podría generar la excepción. } catch(sqlexception e) { // Descripción del error System.out.println("Message: " + e.getmessage()); // identificación del error System.out.println("SQLState: " + e.getsqlstate()); // Código de error del vendedor System.out.println("ErrorCode: " + e.geterrorcode()); }...

)1 4 5 @... PreparedStatement stmt; ResultSet result; Connection conn;... try { // Aquí va el código que podría generar la excepción. // y que hace uso de stmt, result y conn } catch (SQLException e) { System.out.println("Message: " + e.getmessage()); System.out.println("SQLState: " + e.getsqlstate()); System.out.println("ErrorCode: " + e.geterrorcode()); } finally { conn.close(); if (result!= null) {result.close();} if (stmt!= null) {stmt.close();} }...

9 -*

- 4 -*5 :% &'' ( 3 * : E3 : ' : : * $: 4 )

2 - %!! "$ " #!

6 & '( )(* )+'(* )+)( $ )+,(-,(&.%/ 0(&.%/ 1(& 1+'(*.%/ 1+)(*.%/ 1+,(&

2* <<Class Model>> domain -customerid:string -name:string -surname:string Customer +getcustomerid():string +setcustomerid(customerid:string):void +getname():string +setname(name:string):void +getsurname():string +setsurname(surname:string):void Created with Poseidon for UML Community Edition. Not for Commercial Use.

2* data <<Class Model>> << interface >> ICustomerDAO +selectcustomer(customerid:string):customer +insertcustomer(c:customer):void +deletecustomer(customerid:string):void +selectallcustomers():list XMLCustomerDAO JDBCCustomerDAO JDBCConnectionManager << create >>+JDBCCustomerDAO():JDBCCustomerDAO +selectcustomer(customerid:string):customer +deletecustomer(customerid:string):void +insertcustomer(c:customer):void +selectallcustomers():list #finalize():void uses -dburi:string= "jdbc:mysql://127.0.0.1:3306/pos" -drivername:string= "com.mysql.jdbc.driver" -password:string= "practica" -username:string= "practica" << create >>+ConnectionManager():JDBCConnectionManager +getinstance():jdbcconnectionmanager +checkout():connection +checkin(conn:connection):void #finalize():void - cm Created with Poseidon for UML Community Edition. Not for Commercial Use.

787 9 *: +; F..