JAVA DATABASE CONNECTIVITY(JDBC)
BY
SA’IDU UMMIKULTHUM AMINU CFJ/ND/COM/2022/411
A COM 211 TECHNICAL PAPER ON THE VARIOUS TYPES OF DATABASE THAT ARE BEING USED
IN SYSTEM AND SOFTWARE DEVELOPMENT. WITH A FOCUS ON JAVA DATABASE CONNECTIVITY
(JDBC), AND ALL OTHER DBMS AND DATABASE DRIVERS SUPPORTED AND USED BY/IN JAVA.
MARCH 2024
1
Table of Contents
Introduction to JDBC
Aim and objectives.........................................................................................................................3
Literature Review...........................................................................................................................3
JDBC Architecture
Description:
Application....................................................................................................................................5
The JDBC API................................................................................................................................5
DriverManager...............................................................................................................................5
JDBC drivers..................................................................................................................................5
Types of JDBC Architecture
Two tiers model.............................................................................................................................5
Three tiers model...........................................................................................................................6
Conclusion:
Reference:
2
Introduction
Java Informational collection Organization (JDBC) is a standard association point for
sending addressing and reviving results to the even data that is taken care of in a social
informational index. Although JDBC and ODBC are very similar, JDBC is designed
specifically for Java, whereas ODBC can be used with any language. ODBC uses a data set
driver to accomplish this. The driver transforms the application's request into an order that
the DBMS can comprehend. The DBMS follows the instructions in the solicitation and
transforms the result into something that the application can understand. T Coordinated
Question Language (SQL) is the standard informational collection cooperation language. A
variety of information base operations are carried out. SQL can run most of current data set
frameworks, including Microsoft Access, Prophet, and MySQL. JDBC's goal is to make it
feasible for Java applications to send SQL proclamations to a particular information base
and get results.
Aims and Objectives:
This report's essential goal is to give a top to bottom examination of the different sorts of
data sets utilized in programming and framework improvement. The report specifically
intends to:
3
Examine the significance of databases in the development of software and systems. Inspect
the data set administration elements and utilizations of Java Data set Availability (JDBC).
Literature Review:
Informational collections expect a basic part in system and programming improvement,
filling in as storage facilities for taking care of and supervising data gainfully. As shown by
Date (2003), informational indexes give a coordinated method for managing data limit and
recuperation, working with steady blend in with programming applications (p. 12). Various
databases are used throughout the development process, each with its own set of features
and capabilities tailored to meet specific requirements.
Architecture of Java Database Connectivity(JDBC)
fig: 1
4
Description:
Application: It is a java applet or a servlet that communicates with a data source.
The JDBC API: The JDBC API allows Java programs to execute SQL statements and
retrieve results. Some of the important classes and interfaces defined in JDBC API are
as follows:
DriverManager: It plays an important role in the JDBC architecture. It uses
some database-specific drivers to effectively connect enterprise applications to
databases.
JDBC drivers: To communicate with a data source through JDBC, you need a JDBC driver
that intelligently communicates with the respective data source.
Types of JDBC Architecture(2-tier and 3-tier)
Two-tier model: A java application communicates directly to the data source. The JDBC
driver enables the communication between the application and the data source. When
a user sends a query to the data source, the answers for those queries are sent back
the user in the form of results.
The data source can be located on a different machine on a network to which a user is
connected. This is known as a client/server configuration, where the user’s machine
5
acts as a client, and the machine has the data source running acts as the server.
fig:2
2. Three-tier model: In this, the user’s queries are sent to middle-tier services, from
which the commands are again sent to the data source. The results are sent back to the
middle tier, and from there to the user.
This type of model is found very useful by management information system directors.
fig: 3
Java Database Connectivity (JDBC) is one of the most well-known data set advancements
utilized in Java development. According to Horstmann and Cornell (2018) (p.), JDBC is a
6
standard Java programming language interface for interacting with relational databases. (p.
874). It engages Java applications to execute SQL requests, in this way working with steady
coordination with arranged data base structures.
DBMS options include Microsoft Access, MySQL, Oracle, and others. Each DBMS comes with
its own set of features and components. For example, Prophet is notable for its vigor and
versatility, making it appropriate for applications at the undertaking level (Ramakrishnan
and Gehrke, 2003, p. 41). On the other hand, MySQL is esteemed for its straightforwardness
and comfort, particularly for electronic applications (DuBois, 2003, p. 5).
Likewise, the coordination of JDBC with different DBMS is fundamental for ensuring
comparability and interoperability. JDBC drivers go about as middle people, working with
correspondence between Java applications and secret data base systems. There are four
kinds of JDBC drivers: Type 1 (JDBC-ODBC range), Type 2 (nearby Programming
connection point to some degree Java development enabled driver), Type 3 (network show
driver), and Type 4 (small driver) (Horstmann and Cornell, 2018, p. 877). With regards to
execution, compactness, and organization contemplations, every driver type offers
particular benefits.
In addition, SQL fills in as the most broadly involved language for informational collection
participations, offering a standardized syntax for executing informational index
7
undertakings. According to Silberschatz, Korth, and Sudarshan (2010) (p.), SQL enables
developers to perform a variety of tasks, including data manipulation, definition, and
control (p. 5). Its versatility and similitude with different DBMS make it essential in
programming improvement.
With everything taken into account, informational indexes are indispensable pieces of
system and programming improvement, working with capable data the board and
recuperation. To make it feasible for Java applications and social data sets to consistently
coordinate, JDBC, notwithstanding various DBMSs and information base drivers, assumes a
significant part. The gathering of SQL further redesigns the capacities of informational
collection systems, enabling originators to execute arranged exercises as a matter of fact.
Conclusion:
how effectively databases are utilized determines the success of software and system
development projects. Java Informational collection Organization (JDBC) fills in as an
establishment in engaging Java applications to reliably help out friendly informational
collections. Engineers approach a large number of information stockpiling and recovery
choices because of JDBC drivers and an assortment of Data set Administration Frameworks
(DBMS). Also, the normalization of Organized Question Language (SQL) further develops
information base framework interoperability and similarity across stages. As such, a
8
thorough understanding of these informational index developments is essential for present
day programming improvement practices.
References:
1. Date, C. J. (2003). A Preamble to Data base Structures. Addison-Wesley.
2. DuBois, P. (2003). MySQL. Addison-Wesley. C. Horstmann and G. Cornell (2018).
Focus Java SE 9 for the Fretful. Addison-Wesley.
3. R. J. and Ramakrishnan Gehrke (2003). Frameworks for database administration.
McGraw-Hill.
4. A. Silberschatz and H. Korth F., and Sudarshan, S. (2010). Database system concepts.
McGraw-Hill.
5. Date, C. J. (2003). An Outline of Data set Frameworks Addison-Wesley.
6. P. DuBois (2003). MySQL. Addison-Wesley.
7. Horstmann, C., and Cornell, G. (2018). Java SE 9 Center for the Nervous Addison-
Wesley.
8. R. Ramakrishnan and J. Gehrke's 2003 work Data base Organization Systems.
McGraw-Hill.
9. A. Silberschatz and H. Korth F., and Sudarshan, S. (2010). Informational collection
System Thoughts. McGraw-Hill.
9
10. Lewis, W. J. (2000). Java Database Best Practices. O'Reilly Media. (JDBC). Addison-
Wesley.
program
11. import java.sql.*;
12.
13. public class RegistrationFormViewer {
14.
15. // JDBC URL, username, and password
16. static final String JDBC_URL = "jdbc:mysql://localhost:3306/";
17. static final String DB_NAME = "registration_form";
18. static final String USERNAME = "your_username";
19. static final String PASSWORD = "your_password";
20.
21. public static void main(String[] args) {
22. try {
23. // Connect to MySQL database
24. Connection connection = DriverManager.getConnection(JDBC_URL,
USERNAME, PASSWORD);
25.
10
26. // Create database if it doesn't exist
27. createDatabase(connection);
28.
29. // Create table if it doesn't exist
30. createTable(connection);
31.
32. // Display existing registration form data
33. displayRegistrationFormData(connection);
34.
35. // Insert new registration form data
36. insertRegistrationData(connection, "John", "Doe", "ABC123", 25, "Male",
"Computer Science");
37.
38. // Display updated registration form data
39. displayRegistrationFormData(connection);
40.
41. // Close connection
42. connection.close();
43.
44. } catch (SQLException e) {
45. e.printStackTrace();
46. }
47. }
11
48.
49. // Method to create database if it doesn't exist
50. private static void createDatabase(Connection connection) throws SQLException {
51. try (Statement statement = connection.createStatement()) {
52. String sql = "CREATE DATABASE IF NOT EXISTS " + DB_NAME;
53. statement.executeUpdate(sql);
54. }
55. }
56.
57. // Method to create table if it doesn't exist
58. private static void createTable(Connection connection) throws SQLException {
59. try (Statement statement = connection.createStatement()) {
60. String sql = "CREATE TABLE IF NOT EXISTS " + DB_NAME +
".registration_data (" +
61. "id INT AUTO_INCREMENT PRIMARY KEY," +
62. "first_name VARCHAR(50) NOT NULL," +
63. "last_name VARCHAR(50) NOT NULL," +
64. "matric_number VARCHAR(20) NOT NULL," +
65. "age INT NOT NULL," +
66. "gender VARCHAR(10) NOT NULL," +
67. "department VARCHAR(50) NOT NULL)";
68. statement.executeUpdate(sql);
69. }
12
70. }
71.
72. // Method to display registration form data
73. private static void displayRegistrationFormData(Connection connection) throws
SQLException {
74. try (Statement statement = connection.createStatement()) {
75. ResultSet resultSet = statement.executeQuery("SELECT * FROM " + DB_NAME
+ ".registration_data");
76.
77. System.out.println("Registration Form Data:");
78. System.out.println("ID\tFirst Name\tLast Name\tMatric
Number\tAge\tGender\tDepartment");
79.
80. while (resultSet.next()) {
81. int id = resultSet.getInt("id");
82. String firstName = resultSet.getString("first_name");
83. String lastName = resultSet.getString("last_name");
84. String matricNumber = resultSet.getString("matric_number");
85. int age = resultSet.getInt("age");
String gender = resultSet.getString("gender");
String department = resultSet.getString("department");
13