Sobes.tech
Junior — Middle

Can you list the main interfaces used in JDBC for working with databases?

sobes.tech AI

Answer from AI

Main JDBC interfaces for working with databases:

  • Driver — interface for implementing the database driver.
  • Connection — represents a connection to the database, used to create queries.
  • Statement — used to execute SQL queries without parameters.
  • PreparedStatement — an extension of Statement, allows executing parameterized queries, increasing security and performance.
  • CallableStatement — used to invoke stored procedures.
  • ResultSet — represents the result of a query execution, allows iterating over the result rows.

Example of usage:

Connection conn = DriverManager.getConnection(url, user, password);
PreparedStatement ps = conn.prepareStatement("SELECT * FROM users WHERE id = ?");
ps.setInt(1, 10);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
    System.out.println(rs.getString("username"));
}
rs.close();
ps.close();
conn.close();
Can you list the main interfaces used in JDBC for… - sobes.tech