Recent Pos

The JDBC Statement PreparedStatement and CallableStatement Object

Facebooktwittergoogle_plusredditpinterestlinkedintumblrmail

jdbc statement preparedstatement callablestatement
⇒ The JDBC Statement PreparedStatement and CallableStatement is an interface in Java. All database vendors implement these interface and provide the JAR according to their logic.

⇒ Java application wants to access the database server for performing CRUD(Create, Read, Update, Delete) operations.

⇒ We know that the SQL is a standard language that most of the database servers support.

⇒ The JDBC statement is used to represent the Statement executing to the database server.

We have 3 types of JDBC Statement:

1. Statement

2. PreparedStatement

3. CallableStatement

⇒ The Statement object is a JDBC Driver object that can represent a simple static SQL statement executing to the database server.

⇒ The java.sql.Statement interface of JDBC API is used to describe the Statement object.
Step 1: Get the Connection object using the database
Note: We discussed about getting connection in previous post

Step 2: Get the Statement:
We use the following method of Connection object to create the Statemnt object:

Statement createStatement()
Example:

Q. What is Connection?

⇒ It is a JDBC Driver object representing the session established to the database server.

⇒ The successful outcome of Step 1 (i.e. Obtaining Connection to DB is the Connection object).

⇒ The java.sql.Connection interface implementation object is the Connection object.

Using the “Statement” object to execute the SQL Statements:

The following are the three methods of Statement available to execute the SQL Statements:

The executeUpdate() method:

⇒ This method is used to execute any SQL Statement other than “select”

⇒ This returns int value which specifies the number of records effected by executing the given statement.

⇒ The int value possibly >=0 : specifies the no. of records effected successfully.

Statement.SUCCESS_NO_INFO: specifies the Statement is executed successfully but the no. of records effected are not known(int value -2).

Note: In case if the Statement fails to execute this throws SQLException.

Example:

<-Previous: DAO (Data Access Object) pattern implementation using JDBC | | Next->Example Application for CRUD Operations Using JDBC

No Comments

Post a Comment