38
ADO ActiveX Data Object

ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Embed Size (px)

Citation preview

Page 1: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

ADOActiveX Data Object

Page 2: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

• ActiveX Data Objects (ADO) is Microsoft’s latest database object model.

• The goal of ADO is to allow VB developers to use a standard set of objects to refer to any OLE DB source.

• Is Microsoft ActiveX Component.

• Automatically installed with Microsoft IIS Server

• ADO is a programming interface to access data in a database

ADO

Page 3: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

ActiveX Data Objects (ADO)

• Performs same functions as ADO with following improvements:–Simpler command set–Faster execution (sometimes)–Uses less memory–Consumes less disk space–Supports any database to which Access can

connect

Page 4: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Universal Data Access (UDA)

• It supports high performance data access to relational , nonrelational, and legacy data sources.

• Components– The OLE DB– The Core of the UDA architecture– Provides low level access to any data source

Page 5: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Microsoft UDA Architecture

Page 6: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Connection Command Recordset

Errors

Error

Parameters

Parameter

Fields

Field

ADO Objects

Connection Allows control over the connection to the data source

Recordset Contains the records that are the result of a query

Command Executes database commands and queries

Error Contains information about Errors from ADO

Field Represents a field in a data set

Parameter Works with Command to set parameters for stored procedures or parameter queries

Property Allows you to access ADO object Properties

Page 7: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Before using ADO, you must establish a reference to the ADO library.

Project, References, Microsoft ActiveX Data Objects 2.5 Library

Establish Reference to ADO

Page 8: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

1. Create a Connection Object.  

2. Specify the connection string to connect to the database of interest.  3. Open the connection 4. Create a Recordset object. The Recordset object contains the results of

the query after execution. 5. Specify the SQL text. When you open a recordset, you can either use a

table, a stored procedure, or string containing a SQL statement. 6. Open the recordset.

7. Opening the recordset executes the query and returns the records to the recordset object. The records are accessible through the recordset object now.

Basic Steps to executing a query using ADO

Page 9: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

A Connection object represents a unique session with a data source. In the case of a client/server database system, it may be equivalent to an actual network connection to the server.

 Important Properties and Methods 

• ConnectionString• ConnectionTimeout• Mode  • CursorLocation • Provider • Open and Close

Connection Object

Page 10: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Create ADODB Connection

Dim connAVB As ADODB.Connection

Set connAVB = New ADODB.Connection

connAVB.ConnectionString = "Provider = Microsoft.Jet.OLEDB.3.51;" & "Data Source=" & App.Path & "\AVB.mdb;Mode=readwrite“

connAVB.Open

Connection Object

Page 11: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

'Create ADODB Connection

Dim connAVB As ADODB.Connection

Set connAVB = New ADODB.Connection

connAVB.ConnectionString = "Provider = Microsoft.Jet.OLEDB.3.51;" & "Data Source=" & App.Path & "\AVB.mdb;Mode=readwrite“

connAVB.Open

‘code

connAVB.CloseSet connAVB = Nothing

Connection Object

Page 12: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Represents the entire set of records from a base table or the results of an executed command.  

You use Recordset objects to manipulate data from a provider.

Important Properties and Methods• CursorLocation• CursorType• LockType• Mode• Open, Close• MoveFirst, MoveLast, MoveNext, and MovePrevious • BOF, EOF• Update, AddNew, Delete• GetString, GetRows

Recordset Object

Page 13: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Cursor refers to system resources needed to manage a set of data.

Specifies the location of the cursor service.Constant Value Description adUseClient -Uses client-side cursors supplied by a local

cursor. Use for desktop applications.

adUseServer - Default. Uses data-provider or driver-supplied cursors.

These cursors are sometimes very flexible and allow for additional sensitivity to changes others make to the data source.

CursorLocation

Page 14: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Dynamic cursor — allows you to view additions, changes, and deletions by other users; allows all types of movement through the Recordset

Keyset cursor — behaves like a dynamic cursor, except that it prevents you from seeing records that other users add, and prevents access to records that other users delete. Data changes by other users will still be visible.

Static cursor — provides a static copy of a set of records for you to use to find data or generate reports; always allows bookmarks and therefore allows all types of movement through the Recordset. Additions, changes, or deletions by other users will not be visible. This is the only type of cursor allowed when you open a client-side Recordset object.

Forward-only cursor — allows you to only scroll forward through the Recordset. Additions, changes, or deletions by other users will not be visible. This improves performance in situations where you need to make only a single pass through a Recordset.

Cursor Types

Page 15: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

LockType is important when you have multiple users accessing the samedata.

Lock Types

Lock Type Constant Result

N/A adLockUnSpecified

Read Only adLockReadOnly No edits

Optimistic adLockOptimistic Locked as each update submitted.

BatchOptimistic adLockBatchOptimistic Locked when all updates submitted

Pessimistic adLockPessimistic Locked from Recordset creation

Page 16: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Public Sub MoveX() ' connection and recordset variables Dim rstAuthors As ADODB.Recordset Dim Cnxn As ADODB.Connection Dim strCnxn As String Dim strSQLAuthors As String ' Open connection Set Cnxn = New ADODB.Connection strCnxn = "Provider=sqloledb;Data Source=a-iresmi2000;Initial

Catalog=pubs;User Id=sa;Password=;" Cnxn.Open strCnxn ' Open recordset from Authors table Set rstAuthors = New ADODB.Recordset rstAuthors.CursorLocation = adUseClient

Opening a RecordSet

Page 17: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

strSQLAuthors = "SELECT au_id, au_fname, au_lname, city, state FROM Authors ORDER BY au_lname”

rstAuthors.Open strSQLAuthors, strCnxn, adOpenStatic, adLockOptimistic, adCmdText

rstAuthors.MoveFirst numRecords = rstAuthors.RecordCount city = rstAuthors!city

rstAuthors.Close Cnxn.Close Set rstAuthors = Nothing Set Cnxn = NothingEnd Sub

Opening a RecordSet

Page 18: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

ADO.NET

• ADO.NET is a new, improved, and greatly expanded version of ADO that was developed for the Microsoft .NET initiative

• It incorporates all of the functionality of ADO and facilitates the transformation of XML documents to and from database data

• It uses datasets, which is an in-memory, fully-functioned, independent databases

Page 19: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Role of ADO.NET

• ADO.NET serves as an intermediary between all types of .NET applications and the DBMS and database

Page 20: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Data Provider

• A .NET data provider is a library of classes that provides ADO.NET services

• Microsoft’s provides three data providers– OLE DB data provider can be used to process any OLE

DB-compliant data source– SQLClient data provider is purpose-built for use with SQL

Server– OracleClient data provider is purpose-built for use with

Oracle

Page 21: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Data Provider Components

Page 22: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Data Provider Components

• A connection object is similar to the OBDC’s connection object

• A command object is created on an established connection

• A data reader provides read-only, forward-only, fast access to database data

• An application can get and put data to and from the database using the command object

• A dataset is an in-memory database that is disconnected from any regular database – It distinguishes ADO.NET from the previous data access

technology

Page 23: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

The ADO.NET Dataset

• A dataset is an in-memory database that is disconnected from any regular database

• Datasets can have – Multiple tables, views, and relationships

• Tables may have surrogate key (auto increment columns), primary keys, and be declared as unique

– Referential integrity rules and actions– The equivalent of triggers

• Datasets may be constructed from several different databases and managed by different DBMS

Page 24: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Dataset Advantages

• Dataset contents and its XML schema can be easily formatted as an XML document

• Also, XML schema documents can be read to create the structure of the dataset, and XML documents can be read to fill the dataset

• Datasets are needed to provide a standardized, non-proprietary means to process database views– This is important for the processing of views with

multiple multi-value paths

Page 25: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Dataset Disadvantages

• Because dataset data are disconnected from regular database, only optimistic locking can be used when updating the regular database with the dataset

• In the case of conflict, either the dataset must be reprocessed or the data change must be forced onto the database, causing the lost update problem

• Thus, datasets cannot be used for applications in which optimistic locking is problematical– Instead, the ADO.NET command object should be used

Page 26: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

JDBC & Servlet

Page 27: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Outline

HTML Forms Redirecting Request to other resources Tomcat Functions in JDBC & Servlet

Page 28: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

HTML FormsAn interface controls to collect data from the user and transmit it to server.

Page 29: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Element in Forms

TEXT CONTROLS:<INPUT TYPE="TEXT" NAME="NAME" VALUE="INIT">

PASSWORD FIELDS:<INPUT TYPE="PASSWORD" NAME="PASSWORD">

TEXT AREAS:<TEXTAREA NAME="RESUME" ROWS=5 COLS=30>INPUT YOUR RESUME HERE </TEXTAREA>

Checkbox<input type="checkbox" name="checkbox" checked><input type="checkbox" name="checkbox">

Radio Button<input type="radio" name="radio" checked><input type="radio" name="radio">

Page 30: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Cont. List

<select name="list">

<option value="Item 1">Item 1</option>

<option value="Item 2">Item 2</option>

<option value="Item 3">Item 3</option>

</select> Multilist

<select name="multilist" size="3" multiple>

<option value="Item 1">Item 1</option>

<option value="Item 2">Item 2</option>

<option value="Item 3">Item 3</option>

</select>

Page 31: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Cont. Submit Button

<input type="submit" name="submit" value="Submit"> Reset Button

<input type="reset" name="reset" value="Reset Fields"> Image Button

<input type="image" name="image" src="go.gif"> File

<input type="file" name="file">

Page 32: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Tomcat A light web server that supports servlet & JSP. It can be integrated in Apache, IIS

Page 33: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

What is JDBC & Servlet?

JDBC (Java DataBase Connectivity) provides functions to access database system.

Servlet enables java for CGI programs. Setup JDBC environment:

Page 34: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

JDBC : Establishing a Connection

loading the driver DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

making the connection String url = "jdbc:oracle:thin:@ra.msstate.edu:1521:ACAD";

Connection con = DriverManager.getConnection(url, “loginName", “Password");

Page 35: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Statement Create a statement Statement stmt = con.createStatement();

Two methods of statement 1. executeUpdate() create, alter, drop a table

Or insert, delete, update data

2. executeQuery() select

Page 36: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Create Table

String createTableCoffees = "CREATE TABLE COFFEES " + "(COF_NAME VARCHAR(32), SUP_ID INTEGER, PRICE FLOAT, " + "SALES INTEGER, TOTAL INTEGER)";

stmt.executeUpdate(createTableCoffees);

Page 37: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Query Data from a Table stmt.executeQuery (“select * from customer”);

ResultSet rs = stmt.executeQuery( "SELECT COF_NAME, PRICE FROM COFFEES");

Page 38: ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard

Display Result Method next() Initially the cursor is above the first row of data. After call the method

next(), the cursor is pointing to the first row of data. A Sample while (rs.next()) { String s = rs.getString ("COF_NAME"); float n = rs.getFloat ("PRICE"); System.out.println (s + " " + n); }

References: http://java.sun.com/docs/books/tutorial/jdbc/index.html