import java.sql.*; public class SimplifiedDBOperations { public static void main(String[] args) { String url = "jdbc:mysql://localhost:3306/testdb"; // Database URL String username = "root"; // DB Username String password = ""; // DB Password // Establish connection Connection connection = null; try { connection = DriverManager.getConnection(url, username, password); // CREATE: Insert a new user String name = "John Doe"; int age = 30; String insert = "INSERT INTO users (name, age) VALUES ('" + name + "', " + age + ")"; Statement stmt = connection.createStatement(); stmt.executeUpdate(insert); System.out.println("User added!"); // READ: Retrieve all users String select = "SELECT * FROM users"; Statement readStmt = connection.createStatement(); ResultSet rs = readStmt.executeQuery(select); while (rs.next()) { System.out.println("ID: " + rs.getInt("id") + ", Name: " + rs.getString("name") + ", Age: " + rs.getInt("age")); } // UPDATE: Update a user's age (assuming id 1 exists) int idToUpdate = 1; int newAge = 35; String update = "UPDATE users SET age = " + newAge + " WHERE id = " + idToUpdate; Statement updateStmt = connection.createStatement(); int rowsAffected = updateStmt.executeUpdate(update); if (rowsAffected > 0) { System.out.println("User updated!"); } else { System.out.println("User not found."); } // DELETE: Delete a user (assuming id 1 exists) int deleteId = 1; String delete = "DELETE FROM users WHERE id = " + deleteId; Statement deleteStmt = connection.createStatement(); int rowsDeleted = deleteStmt.executeUpdate(delete); if (rowsDeleted > 0) { System.out.println("User deleted!"); } else { System.out.println("User not found."); } } catch (SQLException e) { e.printStackTrace(); } finally { try { if (connection != null) connection.close(); } catch (SQLException e) { e.printStackTrace(); } } } } CREATE TABLE users ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100), age INT );