Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 ADO ActiveX Data Object

2 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

3 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

4 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

5 Microsoft UDA Architecture

6 ConnectionCommandRecordset Errors Error Parameters Parameter Fields Field ADO Objects ConnectionAllows control over the connection to the data source RecordsetContains the records that are the result of a query CommandExecutes database commands and queries ErrorContains information about Errors from ADO FieldRepresents a field in a data set ParameterWorks with Command to set parameters for stored procedures or parameter queries PropertyAllows you to access ADO object Properties

7 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

8 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

9 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

10 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

11 '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.Close Set connAVB = Nothing Connection Object

12 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

13 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

14 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

15 LockType is important when you have multiple users accessing the same data. Lock Types Lock TypeConstantResult N/AadLockUnSpecified Read OnlyadLockReadOnlyNo edits OptimisticadLockOptimisticLocked as each update submitted. BatchOptimisticadLockBatchOptimisticLocked when all updates submitted PessimisticadLockPessimisticLocked from Recordset creation

16 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

17 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 = Nothing End Sub Opening a RecordSet

18 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

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

20 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

21 Data Provider Components

22 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

23 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

24 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

25 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

26 JDBC & Servlet

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

28 HTML Forms An interface controls to collect data from the user and transmit it to server.

29 Element in Forms TEXT CONTROLS: PASSWORD FIELDS: TEXT AREAS: INPUT YOUR RESUME HERE Checkbox Radio Button

30 Cont. List Item 1 Item 2 Item 3 Multilist Item 1 Item 2 Item 3

31 Cont. Submit Button Reset Button Image Button File

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

33 What is JDBC & Servlet? JDBC (Java DataBase Connectivity) provides functions to access database system. Servlet enables java for CGI programs. Setup JDBC environment:

34 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");

35 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

36 Create Table String createTableCoffees = "CREATE TABLE COFFEES " + "(COF_NAME VARCHAR(32), SUP_ID INTEGER, PRICE FLOAT, " + "SALES INTEGER, TOTAL INTEGER)"; stmt.executeUpdate(createTableCoffees);

37 Query Data from a Table stmt.executeQuery (“select * from customer”); ResultSet rs = stmt.executeQuery( "SELECT COF_NAME, PRICE FROM COFFEES");

38 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


Download ppt "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."

Similar presentations


Ads by Google