Java Based Middleware IST 421 Java Based Middleware
Java Based Middleware IST 421
Java Based Middleware Six major categories of Java middleware ◦ ◦ ◦ Database oriented Interprocess Message oriented Application hosting Transaction processing Connectivity
Java Based Middleware Information Oriented Integration Database X Interprocess Message Business Process Oriented Integration X Portal Oriented Integration X X X Application Hosting X X X Transaction Processing X X X Connectivity X Service Oriented Integration X
Database Oriented Database oriented java enabled middleware ◦ Oldest ◦ Best supported JDBC specification permit access to most relational databases
Interprocess Java. Soft connects to databases and provides RMI ◦ Simple synchronous mechanism that allows applets to communicate with one another and invoke one another’s methods ◦ Permits sharing information with other applets and servlets throughout an enterprise
Message Oriented Java Message Service (JMS) ◦ Adds a common API which enables Java developer to dispatch and receive messages with other Java applications or applets on the network ◦ Provides messaging features common to most messaging products Three major entities ◦ JMS provider ◦ JMS messages ◦ JMS domains
Message Oriented JMS Messages ◦ Sets of messaging interfaces that define a common mechanism & format for moving information between providers ◦ JMS Message Header – identify & route messages Properties – extra information to a standard header Body – the data being transported
Message Oriented JMS Messages ◦ Point-to-point ◦ Publish/subscribe
Application Hosting Application server is any product that provides a host for application logic and processes all or part of an application.
Connectivity JCA (Java EE Connector Architecture) specification is used for Java
JDBC Java programs communicate with databases using JDBC API JDBC is not an acronym for anything JDBC API has been revised several times ◦ JDBC 3. 0 released on Oct. 26, 2000 ◦ 19 interfaces, 6 classes, 4 exception classes
JDBC www. oracle. com/technetwork/javase/tec h/index-jsp-136101. html Most popular database systems are relational databases ◦ ◦ Microsoft SQL Server Oracle DB 2 My. SQL
Relational Databases Relational databases stores data in tables ◦ Rows representing a record ◦ Columns representing individual fields of data ◦ Primary key is a column or group of columns in a table with a unique value ◦ Select statements to specify which data to look at in a table ◦ Queries used to define what will be selected from a table or group of tables
Relational Databases ◦ Foreign key is a column that is a primary key in another table ◦ Referential Integrity: every foreign key must appear as another table’s primary key SELECT title, edition. Number, copyright FROM Titles WHERE copyright > 2000;
Relational Databases � Other SQL Statements: INSERT INTO Authors (first. Name, last. Name) VALUES ( ‘Sue’, ‘Smith’); UPDATE Authors SET last. Name = ‘Jones’ WHERE last. Name = ‘Smith’ and first. Name = ‘Sue’;
Relational Databases � Other SQL Statements: DELETE FROM Authors WHERE last. Name = ‘Jones’ and first. Name = ‘Sue’;
JDBC Steps to be programmed to access a relational database using Java 1. Load a driver which is compatible with the database being used. 2. Establish a connection to the database 3. Associate an SQL statement with this connection 4. Execute the SQL statement 5. SQL statement will produce a table stored in a Result. Set object.
JDBC 6. When processing is complete, database is closed 7. Connection to the database is closed
JDBC Client/Server Data Access with Java and XML, by D. Chang and D. Harkey, John Wiley & Sons, Inc. , 1998.
JDBC � The JBDC API is contained in the java. sql package import java. sql. *;
JDBC � Driver. Manager Class ◦ Class manages JDBC drivers and provides uniform interface for establishing connections to databases ◦ Load the driver by calling : Class. for. Name(driver. Class. Name); Class. for. Name(“sun. jdbc. odbc. Jdbc. Odbc. Driver”); � If the driver can’t be loaded, a Class. Not. Found. Exception is thrown.
JDBC � If the connection can’t be made, an SQLException is thrown.
JDBC JOption. Pane. show. Message. Dialog( null, cnf. get. Message( ), "Driver Not Found", JOption. Pane. ERROR_MESSAGE ); � Four arguments: ◦ Null – the message dialog will appear in the center of the screen ◦ Second argument is the message to display ◦ Third argument is the string that will appear in the dialog box’s title bar ◦ Fourth argument is the dialog box type, represented by an icon �JOption. Pane. ERROR_MESSAGE �JOption. Pane. INFORMATION_MESSAGE �JOption. Pane. WARNING_MESSAGE �JOption. Pane. QUESTION_MESSAGE �JOption. Pane. PLAIN_MESSAGE
JDBC �A Connection (or session) interface must be implemented Driver. Manager. get. Connection(String url, String user, String password); Driver. Manager. get. Connection (“jdbc: odbc: author”, “jdbc_user”, “guest”);
JDBC ◦ The url provides a mechanism to uniquely identify a database: jdbc: <subprototocl>: <subname> ◦ A JDBC driver needs to understand the subprotocol jdbc: db 2: sample jdbc: oracle: oci 8: @
JDBC � Statement interface ◦ Created from our Connection object ◦ Returns a Statement object Statement db. Statement = null; db. Statement = db. Connect. create. Statement();
JDBC � Whether or not an exception is thrown, always close the connection to the database ◦ Use the finally block to make sure this happens db. Statement. close( ); db. Connect. close( ); �Both throw SQLException �Must be caught in a nested try / catch block
JDBC � Exchange information between the database and a Java program � Statement object is used to send SQL requests ◦ Select, Insert, Update, or Delete statement ◦ Modify the database schema using Create, Alter, or Drop statements
JDBC an SQL query, the execute. Query( ) method is used � If a change to the database is being made, the execute. Update( ) method is used � For Result. Set db. Result = null; String query; query = "SELECT * FROM Customer"; db. Result = db. Statement. execute. Query(query);
JDBC � Send SQL query to database � Database produces the rows that satisfy our query and stores them in the Result. Set object
JDBC � Result. Set object has a cursor indicating the current row ◦ Before any rows have been processed, the cursor references the nonexistent row before the first one ◦ Once all of the rows have been processed, the cursor references the nonexistent row after the last one ◦ Change position of the cursor, the method next( ) is called �Returns true if the cursor currently references a valid row �Returns false if not a valid row
JDBC while (db. Result, next( )) { System. out. println(“The title is “ + db. Result. get. String(“Title”) + “ and it costs “ + db. Result. get. Double(2)); } � get. XXX( ) methods ◦ Result. Set interface has 20+ such methods corresponding to the data type being retrieved ◦ Each method takes either a string or an integer as a parameter ◦ The string is the name of the desired column in the query ◦ The integer is the position (starting with 1) of the desired column
JDBC db. Result. get. Object(i) � get. Object( ) method ◦ Uses the standard SQL to Java data type mapping to map a SQL data type to a Java object type ◦ get. Object (int column. Index) ◦ get. Object (int column. Name)
JDBC � The Result. Set is usually processed in order: ◦ Process each row from first to last ◦ Process the columns in the row in order from left to right
API Summary The most important methods are: ◦ Class. for. Name (String Driver. Name) ◦ Driver. Manager get. Connection (String Driver, String Database. URL) get. Connection (String Driver, String Database. URL, String Username, String Password) ◦ Connection create. Statement( )
API Summary ◦ Statement execute. Query (String SQLQuery) ◦ Result. Set get. XXX (String SQLQuery. Column. Name) get. XXX (int SQLQuery. Column. Number) next( )
- Slides: 36