Sobes.tech
Junior — Middle

How was the last SQL query you used in your project formed?

sobes.tech AI

Answer from AI

In my last project, the SQL query was dynamically constructed using parameterized queries through JDBC PreparedStatement to prevent SQL injection and improve code readability. For example, to select users by role and status, I used the following approach:

String sql = "SELECT * FROM users WHERE role = ? AND status = ?";
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString(1, role);
stmt.setString(2, status);
ResultSet rs = stmt.executeQuery();

This method allows for safe parameter substitution and easy modification of the query when needed.