> For the complete documentation index, see [llms.txt](https://suyashs-organization-3.gitbook.io/csitlabs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://suyashs-organization-3.gitbook.io/csitlabs/7th_semester/advanced-java-programming/class-codes/unit1-6-and-8/src/main/java/unit4.md).

# Unit 4: Database Connectivity

JDBC (Java Database Connectivity)

## Programs

1. [Simple JDBC Program](https://github.com/sthsuyash/CSIT_Labs/blob/main/7th_Semester/Advanced%20Java%20Programming/Class%20Codes/Unit1-6&8/src/main/java/Unit4/JDBC.java)
2. [JDBC Program with Prepared Statement](https://github.com/sthsuyash/CSIT_Labs/blob/main/7th_Semester/Advanced%20Java%20Programming/Class%20Codes/Unit1-6&8/src/main/java/Unit4/PreparedStatementDemo.java)
3. [Rowset](https://github.com/sthsuyash/CSIT_Labs/blob/main/7th_Semester/Advanced%20Java%20Programming/Class%20Codes/Unit1-6&8/src/main/java/Unit4/RowSetDemo.java)
4. [Scrollable and Updatable result sets](https://github.com/sthsuyash/CSIT_Labs/blob/main/7th_Semester/Advanced%20Java%20Programming/Class%20Codes/Unit1-6&8/src/main/java/Unit4/ScrollableAndUpdatableResultSet.java)
5. [Swing Connection with Database](https://github.com/sthsuyash/CSIT_Labs/blob/main/7th_Semester/Advanced%20Java%20Programming/Class%20Codes/Unit1-6&8/src/main/java/Unit4/SwingConnection.java)
6. [Transactions in JDBC](https://github.com/sthsuyash/CSIT_Labs/blob/main/7th_Semester/Advanced%20Java%20Programming/Class%20Codes/Unit1-6&8/src/main/java/Unit4/TransactionsDemo.java)
7. [Sql Escapes](https://github.com/sthsuyash/CSIT_Labs/blob/main/7th_Semester/Advanced%20Java%20Programming/Class%20Codes/Unit1-6&8/src/main/java/Unit4/SqlEscapes.java)

## Running the JDBC program

1. Install MySQL on your machine
2. Create a database of your choice
3. 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)

1. Pull the MySQL image from Docker Hub

   ```bash
   docker pull mysql:latest
   ```
2. Run the MySQL container

   ```bash
   docker run --name mysql-db -e MYSQL_ROOT_PASSWORD=password -p 3306:3306 -d mysql:latest
   ```
3. Access the MySQL container

   ```bash
   docker exec -it mysql-db bash
   ```

   ```bash
   mysql -u root -p
   # The password is "password"
   ```
4. Create a database

   ```sql
   CREATE DATABASE primecsitb; -- or any name you want
   ```
5. Run the JDBC program
