1. Trang chủ
  2. » Giáo án - Bài giảng

Chương 3 Database Programming JDBC

90 329 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Cấu trúc

  • Môn Lập trình Java NC

  • Content

  • 0. Introduction

  • 0. Introduction (cont.)

  • Slide 5

  • Slide 6

  • Slide 7

  • Slide 8

  • Slide 9

  • Slide 10

  • 1. The design of JDBC

  • 1. The design of JDBC (cont.)

  • Slide 13

  • Slide 14

  • Slide 15

  • Slide 16

  • Slide 17

  • 2. The Structured Query Language

  • 2. The Structured Query Language (cont.)

  • 3. Installing JDBC

  • 3. Installing JDBC (cont.)

  • 4. Basic JDBC programming concepts

  • Slide 23

  • 4. Basic JDBC programming concepts (cont.)

  • Slide 25

  • Slide 26

  • Slide 27

  • Slide 28

  • Slide 29

  • Slide 30

  • Slide 31

  • Slide 32

  • Slide 33

  • 5. Executing Queries

  • 5. Executing Queries (cont.)

  • Slide 36

  • Slide 37

  • Slide 38

  • 6. Scrollable and Updatable ResultSet

  • 6. Scrollable and Updatable ResultSet (cont.)

  • Slide 41

  • Slide 42

  • Slide 43

  • Slide 44

  • Slide 45

  • Slide 46

  • Slide 47

  • Slide 48

  • * Advanced JDBC programming

  • Slide 50

  • Slide 51

  • Slide 52

  • Slide 53

  • Slide 55

  • Slide 56

  • Slide 57

  • Slide 58

  • Slide 59

  • Slide 60

  • Slide 61

  • Slide 62

  • Slide 63

  • Slide 64

  • Slide 65

  • Slide 66

  • 7. Metadata

  • 7. Metadata (cont.)

  • Slide 69

  • Slide 70

  • Slide 71

  • Slide 72

  • Slide 73

  • Slide 74

  • Slide 75

  • Slide 76

  • Slide 77

  • 8. Transactions

  • 8. Transactions (cont.)

  • Slide 80

  • Slide 81

  • Slide 82

  • Slide 83

  • Slide 84

  • 9. Advanced Connection management

  • 9. Advanced Connection management (cont.)

  • Slide 87

  • Slide 88

  • Slide 89

  • Slide 90

Nội dung

Môn Lập trình Java NC Môn Lập trình Java NC Chương 3: Database Programming JDBC Chương 3: Database Programming JDBC 2Object Oriented Programming 2 - Chapter 4: Database Programming ( JDBC) Content Content 0. Introduction 0. Introduction 1. The design of JDBC 1. The design of JDBC 2. The Structured Query Language 2. The Structured Query Language 3. Installing JDBC 3. Installing JDBC 4. Basic JDBC programming concepts 4. Basic JDBC programming concepts 5. Executing Queries 5. Executing Queries 6. Scrollable and Updatable ResultSet 6. Scrollable and Updatable ResultSet 7. Metadata 7. Metadata 8. Transactions 8. Transactions 9. Advanced Connection management 9. Advanced Connection management 3Object Oriented Programming 2 - Chapter 4: Database Programming ( JDBC) 0. Introduction 0. Introduction  Database Database  Collection of data Collection of data  DBMS DBMS  Database management system Database management system  Stores and organizes data Stores and organizes data  SQL SQL  Relational database Relational database  Structured Query Language Structured Query Language 4Object Oriented Programming 2 - Chapter 4: Database Programming ( JDBC) 0. Introduction (cont.) 0. Introduction (cont.)  RDBMS RDBMS  Relational database management system Relational database management system  Relational database Relational database  Table Table  Rows, columns Rows, columns  Primary key Primary key  Unique data Unique data 5Object Oriented Programming 2 - Chapter 4: Database Programming ( JDBC) 0. Introduction (cont.) 0. Introduction (cont.) ODBC overview ODBC overview  ODBC is an API introduced by Microsoft that allows ODBC is an API introduced by Microsoft that allows applications to access databases by using SQL. applications to access databases by using SQL.  By using ODBC, a single application can access remote By using ODBC, a single application can access remote databases under different DBMSs (i.e. Informix, Oracle, databases under different DBMSs (i.e. Informix, Oracle, Sybase) Sybase)  ODBC relies on data drivers to convert the ODBC calls to ODBC relies on data drivers to convert the ODBC calls to different database formats. different database formats. 6Object Oriented Programming 2 - Chapter 4: Database Programming ( JDBC) 0. Introduction (cont.) 0. Introduction (cont.) ODBC overview (cont.) ODBC overview (cont.)  At development time, the application developer only needs At development time, the application developer only needs to know the ODBC calls to connect to a database, execute to know the ODBC calls to connect to a database, execute SQL statements, and retrieve results. SQL statements, and retrieve results.  Main Components of ODBC: Main Components of ODBC:  Application Application  Driver manager Driver manager  Driver Driver  Target-database middleware Target-database middleware 7Object Oriented Programming 2 - Chapter 4: Database Programming ( JDBC) 0. Introduction (cont.) 0. Introduction (cont.) ODBC overview (cont.) ODBC overview (cont.)  Application : Application :  Requests a connection with a target database Requests a connection with a target database  Passes one or more SQL statements Passes one or more SQL statements  Processes the produced results or error conditions Processes the produced results or error conditions  Ends each transaction with a commit or rollback Ends each transaction with a commit or rollback  Terminates the connection. Terminates the connection. 8Object Oriented Programming 2 - Chapter 4: Database Programming ( JDBC) 0. Introduction (cont.) 0. Introduction (cont.) ODBC overview (cont.) ODBC overview (cont.)  Driver Manager Driver Manager : :  Loads drivers on an as-needed basis for Loads drivers on an as-needed basis for applications applications  Maps a target database name to a specific driver Maps a target database name to a specific driver  Processes several ODBC initialization calls Processes several ODBC initialization calls  Validates the parameters and sequences of ODBC Validates the parameters and sequences of ODBC calls calls 9Object Oriented Programming 2 - Chapter 4: Database Programming ( JDBC) 0. Introduction (cont.) 0. Introduction (cont.) ODBC overview (cont.) ODBC overview (cont.)  Driver : Driver :  Processes the ODBC function calls Processes the ODBC function calls  Modifies them to the target database format Modifies them to the target database format  Submits the SQL statements to the target database, Submits the SQL statements to the target database, receives the results, and presents the results to the receives the results, and presents the results to the application. application. 10Object Oriented Programming 2 - Chapter 4: Database Programming ( JDBC) 0. Introduction (cont.) 0. Introduction (cont.) ODBC overview (cont.) ODBC overview (cont.)  Target-Database Middleware : Target-Database Middleware :  Includes the database needed by the applications Includes the database needed by the applications and the associated middleware and the associated middleware  Database may be located on the same machine or Database may be located on the same machine or remote machine. remote machine. [...]... your database from specifie folder  Press OK to finish  Object Oriented Programming 2 - Chapter 4: Database Programming ( 21 4 Basic JDBC programming concepts  Database URLs:  When connecting to a database, you must specify the data source and you may need to specify additional parameters Object Oriented Programming 2 - Chapter 4: Database Programming ( 22 4 Basic JDBC programming concepts  Database. .. Oriented Programming 2 - Chapter 4: Database Programming ( 13 RDBMS 1 The design of JDBC (cont.) Object Oriented Programming 2 - Chapter 4: Database Programming ( 14 1 The design of JDBC (cont.)  JDBC drivers are classified into the following types: type 1 driver translates JDBC to ODBC and relies on an ODBC driver to communicate with the database  type 2 driver is a driver, written partly in the Java programming. .. “sun .jdbc. odbc.JdbcOdbcDriver”; Class.forName(url); 2 Putting database URL: String dbURL= "jdbc: odbc:yourDataSource"; 3 Create Connection object: Connection conn = DriverManager.getConnection(dbURL); Object Oriented Programming 2 - Chapter 4: Database Programming ( 24 4 Basic JDBC programming concepts (cont.)  Connect to Microsoft Access Class.forName("sun .jdbc. odbc.JdbcOdbcDriver"); String database. .. data types are not exactly the same See below:  Object Oriented Programming 2 - Chapter 4: Database Programming ( 30 4 Basic JDBC programming concepts (cont.) Object Oriented Programming 2 - Chapter 4: Database Programming ( 31 4 Basic JDBC programming concepts (cont.) Advanced SQL Types   In addition to numbers, strings, and dates, many databases can store large objects such as images or other data... "jdbc: odbc:Driver= {Microsoft Access Driver (*.mdb)};DBQ=yourDB.mdb"; Connection conn = DriverManager.getConnection( database, "Admin","" ); //do something after connect… Object Oriented Programming 2 - Chapter 4: Database Programming ( 25 4 Basic JDBC programming concepts (cont.)  Connect to Microsoft SQLServer 2000 Object Oriented Programming 2 - Chapter 4: Database Programming ( 26 4 Basic JDBC programming. .. design of JDBC    JDBC is a Java-based counterpart to ODBC JDBC provides a standard API for tool /database developers and makes it possible to write database applications using a pure Java API Database developers will supply JDBC drivers for their databases so that Java programs may access them transparently Object Oriented Programming 2 - Chapter 4: Database Programming ( 11 1 The design of JDBC (cont.)... independent of the actual database, thus simplifying deployment  type 4 driver is a pure Java library that translates JDBC requests directly to a database- specific protocol  Object Oriented Programming 2 - Chapter 4: Database Programming ( 16 1 The design of JDBC (cont.) Object Oriented Programming 2 - Chapter 4: Database Programming ( 17 2 The Structured Query Language   JDBC is an interface to... language  Object Oriented Programming 2 - Chapter 4: Database Programming ( 19 3 Installing JDBC    On Windows, it already include the JDBC/ ODBC bridge driver We can use driver for Ms Access without installing any thing With MS SQL Server 2000, we must install the driver to use for accessing data Object Oriented Programming 2 - Chapter 4: Database Programming ( 20 3 Installing JDBC (cont.)  To configure... API would not be desirable (void pointers) JDBC is easier to learn A Java API like JDBC is needed in order to enable a “pure java” solution Object Oriented Programming 2 - Chapter 4: Database Programming ( 12 1 The design of JDBC (cont.) JDBC Objects and interfaces Java Appl JDBC Runtime Java to C JDBCODBC Driver DB specifics ODBC Driver ODBC APIs Windows 3G/4G Appl ODBC Interface Initialization, Driver... Syntax:  jdbc: subprotocol name:other_stuff subprotocol is used to select the specific driver for connecting to the database The format for the other stuff parameter depends on the subprotocol used You need to look up your vendor's documentation for the specific format  Example : jdbc: odbc:your_Datasource Object Oriented Programming 2 - Chapter 4: Database Programming ( 23 4 Basic JDBC programming . Programming ( JDBC) 1. The design of JDBC 1. The design of JDBC  JDBC is a Java-based counterpart to ODBC JDBC is a Java-based counterpart to ODBC  JDBC provides a standard API for tool/database JDBC. JDBC 1. The design of JDBC 2. The Structured Query Language 2. The Structured Query Language 3. Installing JDBC 3. Installing JDBC 4. Basic JDBC programming concepts 4. Basic JDBC programming concepts 5 Programming 2 - Chapter 4: Database Programming ( JDBC) 1. The design of JDBC (cont.) 1. The design of JDBC (cont.) Java Appl. JDBC Runtime JDBC- ODBC Driver ODBC Driver RDBMS ODBC Interface ODBC Runtime Windows 3G/4G Appl. DB specifics Java

Ngày đăng: 13/05/2014, 11:01

TỪ KHÓA LIÊN QUAN

w