Sobes.tech
Junior — Middle

What mechanisms and tools do you use for working with databases?

sobes.tech AI

Answer from AI

For working with databases, I use the following mechanisms and tools:

  • JDBC (Java Database Connectivity): a standard API for connecting and executing SQL queries from Java applications.
  • ORM frameworks (e.g., Hibernate, JPA): allow working with the database through objects, simplifying mapping and data management.
  • Schema migration tools: Flyway or Liquibase for version control of the database and automatic application of changes.
  • SQL clients: such as DBeaver, pgAdmin for manual query execution and administration.
  • Connection pools: HikariCP or others for efficient connection management.

Example of connection via JDBC:

String url = "jdbc:postgresql://localhost:5432/mydb";
String user = "user";
String password = "pass";

try (Connection conn = DriverManager.getConnection(url, user, password)) {
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT * FROM users");
    while (rs.next()) {
        System.out.println(rs.getString("username"));
    }
}