Unit N: Distributed Computing - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

Unit N: Distributed Computing

Description:

Unit N: Distributed Computing. Areas to be covered: Java database connectivity ... 1. Java Database Connectivity ... a database connectivity mechanism that may ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 26
Provided by: donfa1
Category:

less

Transcript and Presenter's Notes

Title: Unit N: Distributed Computing


1
Unit N Distributed Computing
  • Areas to be covered
  • Java database connectivity
  • Common object request broker architecture

2
1. Java Database Connectivity
  • A mechanism that allows Java programs to access
    relational databases
  • A Java interface for SQL that supports full
    access to relational databases, including use of
    DDL, DML and Query commands
  • Using JDBC involves
  • Establishing a connection with a database by
    means of a DriverManager and Connection classes
  • Using Statement objects to pass SQL commands to a
    DBMS
  • Processing the results of an SQL query which are
    captured as ResultSet objects

3
Java Database Connectivity
  • The interfaces and classes of JDBC are contained
    in the java.sql package
  • DriverManager manages the loading of JDBC drivers
    and supports new database connections
  • Connection represents database connections
  • Statement represents SQL statements to be passed
    to the DBMS by an established connection
  • ResultSet provides access to the results of a
    query

4
JDBC Driver
  • The DriverManager class is used for loading and
    managing JDBC drivers
  • A JDBC driver must be loaded before any other
    activities can take place
  • The JDBC-ODBC bridge driver provides JDBC access
    via most ODBC drivers
  • A driver is loaded as follows
  • Class.forName(JDBCDriverName)
  • Class.forName(sun.jdbc.odbc.JdbcOdbcDriver)

5
Connecting to Databases
  • JDBC uses URLs to locate databases
  • For a database on the local machine
  • jdbcsubprotocolsubname
  • For a database on a network host
  • jdbcsubprotocol//host port/subname
  • subprotocol specifies a driver or a database
    connectivity mechanism that may be supported by
    one or more drivers
  • subname identifies a database

6
Connection Class
  • Instances of the Connection class represent open
    database connections
  • Connection objects are created by using a static
    method getConnection( ) of the DriverManager
    class
  • The getConnection( ) method takes a JDBC URL, a
    user ID and a password as parameters

7
Connection Class
  • In the following example, the ODBC subprotocol is
    used to access a database named myDatabase
  • String url jdbcodbcmyDatabase
  • Connection conn DriverManager.getConnection(url,
    myID, myPassword)
  • Once the connection has been established, a
    Connection object is returned
  • It can be used to query the database

8
Connection Class
  • Methods
  • createStatement() returns a new Statement object
    for executing SQL statements
  • commit() makes permanent any database changes
    that have been made since the last commit. A
    call to commit also releases any database locks
    held by this Connection object
  • close() releases the DBMS and any other JDBC
    resources currently being used by this Connection
    object

9
Statement Class
  • Instances of the Statement class are used to
    compose SQL commands and send them to a DBMS
  • Statement objects can be obtained from an opened
    database connection
  • Statement stmt conn.createStatement()

10
Statement Class
  • Methods
  • executeQuery(sql) executes the statement sql that
    retrieves data from the database and returns a
    ResultSet object
  • executeUpdate(sql) executes the statement sql
    that updates the database and returns an integer
    indicating the number of rows affected
  • close() releases the DBMS and any other JDBC
    resources currently being used by this Statement
    object
  • The parameter sql is a string that represents an
    SQL command

11
Statement Class
  • To create a table called Beetles
  • String createString CREATE TABLE Beetles (name
    VARCHAR(35), address VARCHAR(30),
  • stmt.executeUpdate(createString)
  • To retrieve the name and email columns of the
    table
  • ResultSet rset stmt.executeQuery(SELECT name,
    email FROM Beetles)

12
ResultSet Class
  • The results of a query are stored as a set of
    rows and columns in a ResultSet object.
  • Methods
  • next() advances to the nest row of the result
    set returns true if successful or false when
    there are no more rows in the result set
  • getType(i) returns the value of the ith column.
    Type is the data type of the column
  • getType(name) retrieves the falues of a column by
    its name
  • void close() releases the DBMS and any other JDBC
    resources currently being used by this ResultSet
    object

13
ResultSet Class
  • The rows of the ResultSet object can be accessed
    by using a combination of the next() method and
    the getType() method
  • The next() method moves the cursor to the next
    row of a ResultSet object and makes that the
    current row
  • Initially the cursor is positioned just above the
    first row so that invoking next() makes the first
    row the current row

14
ResultSet Class
  • There are 2 ways to identify the columns in the
    current row
  • By the column name, or
  • getString(name) returns the name column as a
    String object
  • By the column index
  • getString(1) returns the first column of the
    result set as a String object

15
ResultSet Class
  • The following loop iterates through the rows of
    the ResultSet object, displaying the name and
    email fields
  • while (rset.next())
  • String name rset.getStrin(name)
  • String email rset.getString(email)
  • System.out.println(name , email)

16
Examples
  • Class.forName(sun.jdbc.odbc.JdbcOdbcDriver)
  • // loads the JDBC-ODBC driver
  • String url jdbcodbcOrdersDriver
  • Connection conn DriverManager.getConnection(url,
    rPas,mp9)
  • // connects to the Orders database
  • Statement stmt conn.createStatement()
  • // creates a Statement object

17
Examples
  • String createString CREATE TABLE Beetles (name
    VARCHAR(35), address VARCHAR(30), )
  • stmt.executeUpdate(createString)
  • //builds a new Beetles table
  • String insertString INSERT INTO Beetles VALUES
    (Michael Owen, 123 Elmwood Street,
    )
  • stmt.executeUpdate(insertString)
  • //insert a new row in the Beetles table

18
Examples
  • ResultSet rset stmt.executeQuery(SELECT name,
    email FROM Beetles)
  • // execute a query
  • While (rset.next())
  • System.out.print( rset.getString(name)
    , )
  • System.out.print(rset.getString(2) ,
    )..
  • // print columns as iterate through rows

19
Examples
  • conn.commit()
  • stmt.close()
  • rset.close()
  • conn.close()
  • //close database connection

20
2. CORBA
  • The majority of existing applications are not
    written in Java
  • To interface Java applications with non-Java
    applications in distributed computing
    environments we use a mechanism called CORBA
  • Common Object Request Broker Architecture, an
    open distributed object computing infrastructure
    being standardized by the Object Management Group

21
CORBA
  • Simplifies the development of distributed
    applications by providing a unified view of all
    distributed systems
  • The CORBA application framework provides
    interoperability between objects in heterogeneous
    distributed environments
  • The basic architecture contains server, service
    contract, client, stub and skeleton components

22
CORBA
  • Server is an object that provides services to
    objects residing on remote hosts
  • Service contract is an interface that defines the
    services provided by the server
  • Client is an object that uses services provided
    by objects residing on remote hosts
  • Stub is an object that resides on the same host
    as the client and serves as a proxy of the remote
    server
  • Skeleton is an object that resides on the same
    host as the server. It receives requests from the
    stubs and dispatches the requests to the server

23
CORBA
  • The Interface Definition Language (IDL) is
    central to CORBA
  • The service contract interface of a CORBA server
    is defined in a language-neutral fashion using
    IDL
  • The IDL compilers translate the interfaces
    written in IDL to various implementation
    languages and generate stubs and skeletons in
    various implementation languages

24
CORBA
  • The Object Request Broker (ORB) defines the
    mechanism and interfaces that enable objects to
    make requests and receive responses in a
    distributed environment
  • It provides an infrastructure allowing objects to
    communicate independently of specific platforms
    and implementation languages

25
CORBA
  • A CORBA application consists of a set of
    collaborating objects
  • When a client requests a service, the ORB will
    locate a server that implements the requested
    service. It will also send the arguments and
    call information to the server, invoking the
    method on the server and send the results back to
    the client
  • The client need not be concerned with the server
    objects location, programming language or
    operating system
Write a Comment
User Comments (0)
About PowerShow.com