### Instruction:
Write a Java program that reads data from a MariaDB database table and performs basic CRUD operations (Create, Read, Update, Delete) on the records.


### Response:

To create a Java program that reads data from a MariaDB database table and performs basic CRUD operations, you'll need to follow these steps:

1. Install the MariaDB JDBC driver
2. Set up a MariaDB database and create a table for testing
3. Write the Java code to perform CRUD operations

Here's an example of how to do this:

Step 1: Install the MariaDB JDBC driver

Add the following dependency to your `pom.xml` file if you're using Maven:

```xml
<dependency>
    <groupId>org.mariadb.jdbc</groupId>
    <artifactId>mariadb-java-client</artifactId>
    <version>2.7.3</version>
</dependency>
```

Or add the following to your `build.gradle` file if you're using Gradle:

```groovy
implementation 'org.mariadb.jdbc:mariadb-java-client:2.7.3'
```

Step 2: Set up a MariaDB database and create a table for testing

Create a new database in MariaDB and run the following SQL script to create a sample table called `employees`:

```sql
CREATE TABLE employees (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(50) NOT NULL,
    position VARCHAR(50) NOT NULL,
    salary DECIMAL(10, 2) NOT NULL
);
```

Step 3: Write the Java code to perform CRUD operations

Create a new Java class called `MariaDBCrudExample.java` with the following content:

```java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class MariaDBCrudExample {

    private static final String DB_URL = "jdbc:mariadb://localhost:3306/your_database_name";
    private static final String DB_USER = "your_username";
    private static final String DB_PASSWORD = "your_password";

    public static void main(String[] args) {
        try {
            // 1. Connect to the database
            Connection connection = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);

            // 2. Create a new record (INSERT)
            String insertSql = "INSERT INTO employees (name, position, salary) VALUES (?, ?, ?)";
            PreparedStatement insertStatement = connection.prepareStatement(insertSql);
            insertStatement.setString(1, "John Doe");
            insertStatement.setString(2, "Software Engineer");
            insertStatement.setDouble(3, 80000.0);
            int rowsInserted = insertStatement.executeUpdate();
            System.out.println(rowsInserted + " row(s) inserted.");

            // 3. Read all records (SELECT)
            String selectSql = "SELECT * FROM employees";
            Statement selectStatement = connection.createStatement();
            ResultSet resultSet = selectStatement.executeQuery(selectSql);
            while (resultSet.next()) {
                int id = resultSet.getInt("id");
                String name = resultSet.getString("name");
                String position = resultSet.getString("position");
                double salary = resultSet.getDouble("salary");
                System.out.printf("%d: %s (%s) - $%.2f%n", id, name, position, salary);
            }

            // 4. Update a record (UPDATE)
            String updateSql = "UPDATE employees SET salary = ? WHERE name = ?";
            PreparedStatement updateStatement = connection.prepareStatement(updateSql);
            updateStatement.setDouble(1, 85000.0);
            updateStatement.setString(2, "John Doe");
            int rowsUpdated = updateStatement.executeUpdate();
            System.out.println(rowsUpdated + " row(s) updated.");

            // 5. Delete a record (DELETE)
            String deleteSql = "DELETE FROM employees WHERE name = ?";
            PreparedStatement deleteStatement = connection.prepareStatement(deleteSql);
            deleteStatement.setString(1, "John Doe");
            int rowsDeleted = deleteStatement.executeUpdate();
            System.out.println(rowsDeleted + " row(s) deleted.");

            // 6. Close the connection
            connection.close();

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
```

Replace `your_database_name`, `your_username`, and `your_password` with your actual database name, username, and password.

Now you can run the `MariaDBCrudExample.java` file to see the CRUD operations in action.