Junior — Middle
What level of appropriateness is there in using JDBC for a service that only performs create, read, update, and delete operations?
sobes.tech AI
Answer from AI
Using JDBC for a service that only performs CRUD operations is quite reasonable, especially if direct control over SQL queries and high performance without an additional abstraction layer are required. JDBC provides low-level access to the database, allowing optimization of queries and minimizing overhead. However, if the project involves complex business logic or scalability, consider ORM frameworks that simplify data handling and reduce boilerplate code.
Example of simple JDBC usage for inserting a record:
String sql = "INSERT INTO users (name, email) VALUES (?, ?)";
try (PreparedStatement stmt = connection.prepareStatement(sql)) {
stmt.setString(1, "Ivan Ivanov");
stmt.setString(2, "ivan@example.com");
stmt.executeUpdate();
}