Sobes.tech
Junior — Middle

What tools or technologies do you use to interact with databases?

sobes.tech AI

Answer from AI

To interact with databases in Java, the following tools and technologies are often used:

  • JDBC (Java Database Connectivity) — a standard API for connecting and working with relational databases.
  • ORM frameworks, such as Hibernate — allow working with the database through objects, simplifying the mapping between tables and classes.
  • Spring Data JPA — an abstraction over JPA that simplifies writing repositories and queries.

Example of a simple connection using JDBC:

import java.sql.*;

public class DatabaseExample {
    public static void main(String[] args) throws SQLException {
        String url = "jdbc:mysql://localhost:3306/mydb";
        String user = "root";
        String password = "password";

        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"));
        }

        rs.close();
        stmt.close();
        conn.close();
    }
}
What tools or technologies do you use to interact… - sobes.tech