Mark As Completed Discussion

Connecting to a Database

To connect to a database in Java, we can use JDBC (Java Database Connectivity). JDBC is a Java API that provides a standard way to interact with relational databases.

Here's how we can establish a connection to a MySQL database using JDBC:

TEXT/X-JAVA
1const connection = DriverManager.getConnection(DB_URL, USERNAME, PASSWORD);
JAVA
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment