WEBVTT

00:00.000 --> 00:06.000
Connecting databases to Java applications using JDBC.

00:06.000 --> 00:11.000
In this video, we will understand the purpose of JDBC.

00:11.000 --> 00:14.000
Create and manage a database connection.

00:14.000 --> 00:17.000
Use proper error handling and resource management.

00:17.000 --> 00:20.000
Java database connectivity overview.

00:20.000 --> 00:25.000
JDBC Java database connectivity is important because it enables Java programs

00:25.000 --> 00:30.000
to interact with various databases, such as MySQL, Oracle, or SQLite

00:30.000 --> 00:33.000
using a standardized set of commands.

00:33.000 --> 00:38.000
Instead of learning a new method for every database, JDBC gives us one standard way

00:38.000 --> 00:40.000
to connect and run queries.

00:40.000 --> 00:45.000
To make this work, we use JDBC drivers, which are small programs provided

00:45.000 --> 00:47.000
by each database vendor.

00:47.000 --> 00:52.000
These drivers act as translators between Java and the database.

00:52.000 --> 00:55.000
Establishing a connection.

00:55.000 --> 01:00.000
Now we will create a database with the name of JDBCDB in Workbench.

01:00.000 --> 01:07.000
For this, we need to download the MySQL connector Java.jarr file.

01:07.000 --> 01:12.000
This is the library that will help us connect with the MySQL database.

01:12.000 --> 01:15.000
Download the latest version.

01:15.000 --> 01:18.000
Now we need to open the IDE Eclipse.

01:19.000 --> 01:22.000
We will first create the project.

01:24.000 --> 01:27.000
Then we will create packages.

01:30.000 --> 01:34.000
Create the class within the same package.

01:37.000 --> 01:43.000
Now we will configure the MySQL connector j9.4.0.

01:49.000 --> 01:52.000
This is the library.

01:52.000 --> 01:56.000
In this library, there are all packages, classes, or interfaces,

01:56.000 --> 02:00.000
which is required to connect or perform the connection between the Java application

02:00.000 --> 02:02.000
and MySQL.

02:02.000 --> 02:06.000
Here we have imported the Java and SQL universal packages.

02:06.000 --> 02:09.000
We will first type the code.

02:11.000 --> 02:13.000
This is a type of driver.

02:13.000 --> 02:17.000
It's the medium to connect a Java application to a MySQL database.

02:17.000 --> 02:20.000
It defines how to connect to a specific database,

02:20.000 --> 02:24.000
how to send SQL query, etc.

02:24.000 --> 02:28.000
Here we have created the object for the driver.

02:28.000 --> 02:31.000
Then we registered the driver with the driver manager.

02:31.000 --> 02:35.000
Without a driver manager, we cannot connect with the MySQL database.

02:35.000 --> 02:40.000
This is the built-in class in Java to manage database connections.

02:40.000 --> 02:44.000
Here, dot-get connection will be helping to connect to the specific database

02:44.000 --> 02:46.000
using the driver manager.

02:46.000 --> 02:50.000
Here, JDBC is a type of connectivity.

02:50.000 --> 02:53.000
MySQL is a type of database.

02:53.000 --> 02:58.000
Three, three, zero, six is the default port.

02:58.000 --> 03:01.000
JDBC app is the database name.

03:01.000 --> 03:04.000
Root is the username of MySQL.

03:04.000 --> 03:08.000
This empty string is pass root of MySQL.

03:08.000 --> 03:12.000
If the database username and password are correct,

03:12.000 --> 03:15.000
then it will show the message database is connected.

03:15.000 --> 03:17.000
Let's run the code and check.

03:17.000 --> 03:19.000
Error handling.

03:19.000 --> 03:23.000
For error handling, here we have added SQL exception.

03:23.000 --> 03:28.000
If any error occurs between the Java application and the MySQL database,

03:28.000 --> 03:31.000
then it shows the exact error in the console.

03:31.000 --> 03:35.000
As we fix the error, the message is shown.

03:35.000 --> 03:48.000
JDBC gives Java applications a reliable way to connect to databases,

03:48.000 --> 03:51.000
run queries, and handle data safely.

03:51.000 --> 03:55.000
By understanding connections, queries, and error handling,

03:55.000 --> 04:00.000
you can build secure and functional real-world applications with confidence.

