Sobes.tech
Junior — Middle

What types of operators or commands can be used in JDBC to execute SQL queries?

sobes.tech AI

Answer from AI

In JDBC, three main types of statements are used to execute SQL queries:

  1. Statement — used for executing simple SQL queries without parameters, such as static queries like SELECT, INSERT, UPDATE, DELETE.

  2. PreparedStatement — allows for executing parameterized queries. This enhances security (protection against SQL injection) and performance when executing the same query with different parameters repeatedly.

  3. CallableStatement — used for calling stored procedures in the database.

Example of using PreparedStatement:

String sql = "SELECT * FROM users WHERE id = ?";
PreparedStatement pstmt = connection.prepareStatement(sql);
pstmt.setInt(1, 10);
ResultSet rs = pstmt.executeQuery();
What types of operators or commands can be used in… - sobes.tech