Unit 4: Database Connectivity
JDBC (Java Database Connectivity)
Programs
Running the JDBC program
Install MySQL on your machine
Create a database of your choice
Run the program
Using Docker to run MySQL
If you want to run the JDBC program, but do not want to install MySQL on your machine, you can use Docker to run a MySQL container.
Use the following commands in order to run a MySQL container: (Make sure you have Docker installed on your machine)
Pull the MySQL image from Docker Hub
docker pull mysql:latest
Run the MySQL container
docker run --name mysql-db -e MYSQL_ROOT_PASSWORD=password -p 3306:3306 -d mysql:latest
Access the MySQL container
docker exec -it mysql-db bash
mysql -u root -p # The password is "password"
Create a database
CREATE DATABASE primecsitb; -- or any name you want
Run the JDBC program
Last updated
Was this helpful?