Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ch. NoNameMarks 01AWT24 02Networking18 03JDBC20 04Swing18 05Servlet20 Advance Java Programming.

Similar presentations


Presentation on theme: "Ch. NoNameMarks 01AWT24 02Networking18 03JDBC20 04Swing18 05Servlet20 Advance Java Programming."— Presentation transcript:

1 Ch. NoNameMarks 01AWT24 02Networking18 03JDBC20 04Swing18 05Servlet20 Advance Java Programming

2 2IBM Two-Tier Architecture Client connects directly to server e.g. HTTP

3 Advantage Simple in Design Easy to maintain and modify Communication is fast Disadvantages: Inflexible Limited Client Less secure Cost ineffective

4 4IBM Three-Tier Architecture Application Server sits between client and database User Interface UI Logic Business Logic Database Tables User Data DML Operations Validation Checks Database Server Layer Client Layer Application Server Layer Business Messages Network

5 Advantage Flexible: one part can change without affecting other Can connect to different database High performance Data integrity improve More secure Can implement proxy and firewall

6 Disadvantages High Maintenance High Complexity Lower network efficiency

7 7 Java Application Database The below given figure shows the Employee Logging System application developed in Java interacting with the Employee database using the JDBC API: EmpName E-Mail Address Employee Logging System EmployeeLog NameEmail RDBMS JDBC API Connects to

8 8  It can be categorized into into two layers: Java Application JDBC API Oracle DB2 SQL Server Driver JDBC Application Layer JDBC Driver Layer JDBC Architecture

9 9IBM JDBC Drivers Type I: “Bridge” - Type II: “Native” - Type III: “Middleware” - Type IV: “Pure” - JDBC-ODBC Bridge Driver Native-API Partly-Java Driver JDBC-Net Pure-Java Driver Native Protocol Pure-Java Driver Overview of All Drivers

10 10IBM Type I Drivers Use bridging technology Translates query obtained by JDBC into corresponding ODBC query, which is then handled by the ODBC driver. Almost any database for which ODBC driver is installed, can be accessed.

11 11IBM Disadvantage of Type-I Driver Performance overhead since the calls have to go through the JDBC overhead bridge to the ODBC driver, then to the native db connectivity interface. The ODBC driver needs to be installed on the client machine. Not good for Web

12 12IBM Type II Drivers Native API drivers Better performance than Type 1 since no jdbc to odbc translation is needed. Converts JDBC calls into calls to the client API for that database.

13 13IBM Disadvantage of Type-II Driver The vendor client library needs to be installed on the client machine. Cannot be used in internet due the client side software needed. The driver is compiled for use with the particular operating system. Not good for Web

14 14IBM Type III Drivers Follows a three tier communication approach. Calls middleware server, usually on database host Very flexible -- allows access to multiple databases using one driver Only need to download one driver

15 15IBM Disadvantage of Type-III Driver Requires database-specific coding to be done in the middle tier. An extra layer added may result in a time- bottleneck.

16 16IBM Type IV Drivers 100% Pure Java -- Communicate directly with a vendor’s database through socket connection Use Java networking libraries to talk directly to database engines

17 17IBM Disadvantage of Type-IV Driver At client side, a separate driver is needed for each database

18 18IBM JDBC Process 1.Loading JDBC Driver 2.Connect to Dbms 3.Create Statement object 4.Query execution 5.Process the result 6.Connection termination java.sql package required

19 19IBM Loading Driver User must create database and added under DSN in control panel JDBC driver must be loaded or registered before connecting to dbms Class. forName (“sun.jdbc.odbc.JdbcOdbcDriver”)

20 20IBM Connecting to database DriverManager class is use to make connection to database through DSN Result is stored in object of Connection class DriverManager.getConnection(“ jdbc: odbc:DSN name”) DriverManager.getConnection (“jdbc:odbc:DSN name”, String username, String password)

21 21IBM Create statement object Statements are used to execute sql queries Three types of statement: Statement PreparedStatement CollableStatement Connection class object use to create staement Statement objectname = connection class object.createStataemnt()

22 22IBM Query execution SQL queries are executed to perform operations on database like insert, select etc. It returns ResultSet class object through which database is accessed.

23 23IBM Process the result Different methods are use to accessed rows and columns of table. getX() method is use to obtain value of column of perticular row. getX( column index/name) X may be Int, Float, Boolean, String etc. e.g. getInt(2)

24 24IBM Connection termination Connection are closed using close method.

25 25IBM Methods of Statement class ExecuteQuery()- It used to obtain information form database. Select query is used for this method. Returntype is Object of resultset class e.g. executeQuery(“select * from tablename”)

26 26IBM Methods of Statement class ExecuteUpdate()- It used to perfrom operation on database. Insert, update, delete query is used for this method. Returntype is integer which represent total number of rows affected e.g. executeUpdate(“insert into tablename values”)

27 27IBM Methods of Statement class Execute()- It used to perform any type operation on database. Return type is Boolean If value is true then result stored in resultset object and if value is false then result stored in integer. If true execute getResultSet() and false execute getUpdateCount() method e.g. execute(“insert into tablename values”)

28 28IBM ResultSet This class provides method to access data generated by query in table setX is main method getRow()method use to count total rows

29 29IBM ResultSet Scrollable resultset will move backward or forward first() last() next() absolute (int position) relative(+- int position) Returntype of all methods are boolean To use methods other than next following constants are used ResultSet.TYPE-Scroll_SENSITIVE ResultSet.CONCUR_UPDATABLE

30 30IBM PreparedStatement Query precompiled ? Given on the place of value PreparedStatement objname=connectionobjname.prepareStatement(String query) Value of ? Set using setX method setX(? Position, Value) e.g. setInt(1,10)

31 31IBM CallableStatement Call stored procedures stored in jdbc application program It use three parameter: IN- Input data to procedure OUT- Data return by procedure INOUT- Input as well as output data

32 32IBM MetaData Infromation describe Database or Resultset Types: DatabaseMetaData DatabaseMetaData objname= Connectionobjname.getMetaData() ResultSetMetaData ResultSetMetaData objname= ResultSetobjname.getMetaData()

33 33IBM DatabaseMetaData methods getDatabaseProductVersion() getURL() getDatabaseProductName() getDriverName() getUserName()

34 34 IBM ResultSetMetaData methods getColumnCount() getColumnName(int position) getColumnType(int position) rt: int getTableName(int columnposition) getColumnDisplaySize(int columnposition) getColumnTypeName(int position)

35 35 IBM Exception SQL Exception: if query wrong then exception generated SQL Warning: Provide information about database access warning If data lost due to truncation then TruncationException is thrown


Download ppt "Ch. NoNameMarks 01AWT24 02Networking18 03JDBC20 04Swing18 05Servlet20 Advance Java Programming."

Similar presentations


Ads by Google