### Instruction:
Write a Java program that connects to a PostgreSQL database and performs CRUD operations on a table containing information about books (title, author, publication date, etc.).


### Response:

Here's a Java program that connects to a PostgreSQL database and performs CRUD operations on a table containing information about books (title, author, publication date, etc.). Please make sure you have the PostgreSQL JDBC driver added as a dependency in your project.

```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 BookDatabase {

    private static final String DB_URL = "jdbc:postgresql://localhost:5432/bookdb";
    private static final String USER = "your_username";
    private static final String PASSWORD = "your_password";

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

            // Create the books table if it doesn't exist
            createBooksTable(connection);

            // Insert a book into the table
            insertBook(connection, "The Catcher in the Rye", "J.D. Salinger", "1951-07-16");

            // Update a book's title
            updateBookTitle(connection, 1, "Catcher in the Rye");

            // Retrieve all books from the table
            getAllBooks(connection);

            // Delete a book by ID
            deleteBookById(connection, 1);

            // Close the connection
            connection.close();
        } catch (SQLException e) {
            System.err.println("Error connecting to the database");
            e.printStackTrace();
        }
    }

    private static void createBooksTable(Connection connection) throws SQLException {
        Statement statement = connection.createStatement();
        String sql = "CREATE TABLE IF NOT EXISTS books (" +
                "id SERIAL PRIMARY KEY," +
                "title VARCHAR(255)," +
                "author VARCHAR(255)," +
                "publication_date DATE)";
        statement.executeUpdate(sql);
        statement.close();
    }

    private static void insertBook(Connection connection, String title, String author, String publicationDate) throws SQLException {
        String sql = "INSERT INTO books (title, author, publication_date) VALUES (?, ?, ?)";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, title);
        preparedStatement.setString(2, author);
        preparedStatement.setDate(3, java.sql.Date.valueOf(publicationDate));
        preparedStatement.executeUpdate();
        preparedStatement.close();
    }

    private static void updateBookTitle(Connection connection, int id, String newTitle) throws SQLException {
        String sql = "UPDATE books SET title = ? WHERE id = ?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, newTitle);
        preparedStatement.setInt(2, id);
        preparedStatement.executeUpdate();
        preparedStatement.close();
    }

    private static void getAllBooks(Connection connection) throws SQLException {
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("SELECT * FROM books");

        while (resultSet.next()) {
            System.out.println("ID: " + resultSet.getInt("id") +
                    ", Title: " + resultSet.getString("title") +
                    ", Author: " + resultSet.getString("author") +
                    ", Publication Date: " + resultSet.getDate("publication_date"));
        }

        resultSet.close();
        statement.close();
    }

    private static void deleteBookById(Connection connection, int id) throws SQLException {
        String sql = "DELETE FROM books WHERE id = ?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setInt(1, id);
        preparedStatement.executeUpdate();
        preparedStatement.close();
    }
}
```

Replace `your_username` and `your_password` with your PostgreSQL username and password. This program assumes you have a PostgreSQL server running on localhost at the default port 5432 and a database named `bookdb`. You can change these values in the `DB_URL`, `USER`, and `PASSWORD` constants.

This program demonstrates how to create a table, insert a book, update a book's title, retrieve all books, and delete a book by ID. You can modify the code to perform other CRUD operations as needed.