Nội dung text AJP_SEM-5_CH-2.pdf
Advanced Java Programming A database management system (DBMS) is a software tool used manage and manipulate databases. It provides an interface for interacting with databases, allowing users to store, retrieve,update and delete data. In Java, there are various ways to interact with a DBMS and perform database operations 1. JDBC (Java Database Connectivity): JDBC is a Java API that provides a standard way tointerac with relational databases. It allows you to connect to a DBMS, execute SQL queries, andretrieve the results. JDBC provides a set of classes and interfaces that enable you to establish database connections, create statements, execute queries, and handle the results. 2. ORM (Object-Relational Mapping) Frameworks: ORM frameworks like Hibernate, JPA (Java Persistence API), and MyBatis provide higher-level abstractions for working with databases.These frameworks map Java objects to database tables and handle the underlying SQL operations transparently. They allow you to perform database operations using object-oriented concepts and reduce the need for writing manual SQL queries. you 3. Java APIs for specific databases: Some databases provide their own Java APIs for interacting with their systems. For example, MongoDB has the MongoDB Java driver, which allows to connect to a MongoDB database and perform CRUD (Create, Read, Update, Delete) operations using Java objects and queries specific to MongoDB. 2.1 INTRODUCTION TO JDBC JDBC is a Java API for executing SQL statements. It is a considered as standard for Java Database Connectivity. JDBC consists of a set of classes and interfaces written in Java. Using JDBC, it is easy to send SQL statements to virtually any relational database. The combination of Java and JDBC makes it possible for a programmer to "write it once and run it anywhere". JDBC has continued to evolve alongside the Java platform. The API has been refined to enhance performance, security, and ease of use. JDBC remains the standard Java API for connecting and interacting with relational databases and is widely adopted by Java developers for database connectivity in various applications. Here's a table summarizing the key milestones in the history of JDBC: Year Version 1996 1.0 1997 1.20 1998 2.0 2001 3.0 2006 4.0 2011 4.1 2013 4.2 Key Features and Enhancements Initial release of JDBC with the JDBC-ODBC Bridge driver Improved support for database metadata, scrollable cursors, batch updates Advanced data type support, auto-generated keys, scrollable result sets Savepoints, national character set support, connection pooling, distributed transactions Automatic driver loading, improved exception handling, simplified connection management Try-with-resources statement, connection timeout, driver auto-loading Java 8 date and time types, improved handling of large objects, additional security features These versions represent the major releases of JDBC, each introducing significant enhancements and improvements to the API. 38
40 Advanced Java Programming The JDBC Driver API, which supports the JDBC Manager-to-Driver Connection The JDBC Driver layer consists of the various JDBC drivers responsible for establishing connection between Java applications and specific database management systems ) JDBC drivers implement the JDBC API interfaces and provide the necessary functionality drivers to interact connected with the database to multiple.The different driver manager databases is. capable of supporting multiple concurrent There are four types of JDBC drivers. Each JDBC driver implements the specific mechanisms for establishing connections, executing queries, retrieving results, and functionalities. managing database-specific The JDBC Driver layer acts as the bridge between the Java application and the underlying operations database, . translating JDBC API calls into the appropriate database-specific protocols and 2.2.1 TWO TIER JDBC ARCHITECTURE Two models for database access are supported by the JDBC API. 1. Two-tier model 2. Three-tier model THE TWO-TIER MODEL In the Two-Tier JDBC Architecture, also known as the Client/Server Architecture, the Java application directly communicates with the database server. The key components in this architecture are the Java application (client) and the database server. The Java application handles both the presentation logic and the data access logic. The application establishes a direct connection to the database server using a JDBC driver. . • All database operations, including SQL queries and updates, are executed by the Java application This architecture is suitable for small-scale applications where the database server is directly accessible from the client-side application. Java Applications Client machine JDBC DBMS-properietary protocol DBMS Database server TWO-TIER MODEL . . • the