Easy learning with example program codes

JDBC Statement interface

The JDBC statement is used to execute queries against the database. Statement is an interface which provides the methods to execute queries. We can get a statement object by invoking the createStatement() method of Connection interface.

Statement stmt=conn.createStatement();

Commonly used methods of Statement interface:

1. execute(String SQL): It is used to execute SQL DDL statements.

public boolean execute(String SQL)

2. executeQuery(String SQL): It is used to execute the select query and returns an object of ResultSet.

public ResultSet executeQuery(String SQL)

3. executeUpdate(String SQL): It is used to execute the query like inset, update, delete etc. It returns the no. of affected rows.

public int executeUpdate(String SQL)

4. executeBatch(): It is used to execute the batch of commands.

public int[] executeBatch()

JDBC Statement examples:

1. JDBC Statement creates a table example.

2. JDBC Statement inserts a record example.

3. JDBC Statement updates a record example.

4. JDBC Statement select records example.

5. JDBC Statement deletes a record example.

6. JDBC Statement batch update example.
Next Topic: JDBC Statement creates a table example.
Previous Topic: Connect to MySql database with JDBC driver.


Please follow and like us:
Posted in JDBC   

Copyright © 2019 CodesJava Protection Status