Java Abstract Classes, Interfaces, and JDBC Database Connectivity

Computer science3.03 KB

What Are Abstract Classes?

An abstract class is a class that cannot be instantiated and is used only to define subclasses. A class becomes abstract if at least one of its methods has no implementation. In Java, an abstract method is marked with the abstract keyword.

When to Use Abstract Classes

Abstract classes are used when we want to define an abstraction that encompasses objects of different types and leverage polymorphism.

Understanding Interfaces in Java

An interface is a completely abstract class (a class without implementation). In Java, interfaces are declared with the interface keyword, similar to how abstract classes are declared.

An interface declaration can only contain method declarations (name and signature, without implementation) and definitions of symbolic constants. An interface does not encapsulate data; it only defines the methods that must be implemented by the classes that implement it.

Introduction to SQL

SQL (Structured Query Language) is a declarative language used to access and perform various operations on relational databases.

Java Database Connectivity (JDBC)

Java Database Connectivity (JDBC) is an API that enables the execution of transactions in databases from the Java programming language. It operates independently of the host operating system or the specific database being accessed, using the SQL dialect of the database model in use.

What is an API?

An Application Programming Interface (API) is a set of functions and procedures (or methods, in object-oriented programming) that a library offers for use by other software, serving as an abstraction layer.

Steps to Use JDBC in an Application

  1. Register the JDBC driver.
  2. Establish a connection.
  3. Execute SQL statements.
  4. Process the results.
  5. Close the connection.

What is a JDBC Driver?

A JDBC driver is an implementation of the JDBC API provided by database suppliers. It is typically a .jar file that implements the necessary interfaces.

Types of JDBC Drivers

  • JDBC-ODBC Bridge Driver: Implements JDBC operations by translating them into ODBC calls.
  • Native-API Partly-Java Driver: Converts JDBC calls into calls for other data systems (e.g., Oracle).
  • JDBC-Net Pure Java Driver: Enables dialogue between a negotiator component and databases, often in a 3-tier architecture.
  • Native-Protocol Pure Java Driver: Converts JDBC calls directly into the network protocol used by the Database Management System (DBMS).

Driver Examples

  • MySQL: com.mysql.jdbc.Driver
  • AS400: com.ibm.as400.access.AS400JDBCDriver
  • Oracle: oracle.jdbc.driver.OracleDriver

Download

PDF Word HTML