Posts

Showing posts with the label java.sql Statement

JDBC Statement in Java: Creating Statements and Executing SQL Queries (Execute, ExecuteQuery, ExecuteUpdate)

JDBC Statement in Java In JDBC, a Statement is an interface present in the java.sql package. It is used to send SQL queries from a Java program to a database server. The implementation of the Statement interface is provided by the database vendor (such as MySQL, Oracle, PostgreSQL) inside the JDBC driver JAR file. Creating a JDBC Statement To create a JDBC Statement, a database connection is required. The Connection interface provides the createStatement() method. This method returns an object of a subclass of the Statement interface. Method Syntax: public Statement createStatement(); The returned Statement object is used to execute SQL queries on the database . Executing SQL Queries Using Statement The Statement interface provides different methods to execute SQL queries depending on the query type. 1️⃣ execute(String query) A generic method used to execute any type of SQL query. Can execute DDL, DML, and DQL queries. Examples : CREATE TABLE (DDL) INSERT, UPDATE, DELETE (DML) SELECT (...