Perform Create, Read, Update, and Delete operations on a database using JDBC.
JDBC (Java Database Connectivity) is the standard Java API for connecting to relational databases and executing SQL commands. Performing CRUD (Create, Read, Update, Delete) operations is the foundation of database interaction. The core workflow involves several steps. First, you need to establish a `Connection` to the database using the `DriverManager` class, providing the database URL, username, and password. Once connected, you create a statement object to execute your SQL query. While `Statement` can be used, it's highly recommended to use `PreparedStatement` for any query that involves user input. A `PreparedStatement` is a pre-compiled SQL statement. You use placeholders (`?`) in your SQL query for the parameters. Then, you bind the actual values to these placeholders using setter methods like `setString()` or `setInt()`. This approach is not only more efficient for queries that are executed multiple times but, more importantly, it automatically handles the escaping of special characters, which prevents SQL injection attacks. For `Create` (INSERT), `Update` (UPDATE), and `Delete` (DELETE) operations, you use the `executeUpdate()` method, which returns the number of rows affected. For `Read` (SELECT) operations, you use the `executeQuery()` method, which returns a `ResultSet` object. The `ResultSet` is a table of data representing the query results, which you can iterate through row by row to retrieve the data from each column.