JDBC Statement vs PreparedStatement vs CallableStatement

JDBC Statement, PreparedStatement and CallableStatement are interfaces which provide ways to interact with Databases(Oracle / MySQL / PostGre…etc) with the help of methods in it. But these statements have some difference in terms of features they provide.

JDBC Statement

Used for firing static queries(e.g. select * from table). JDBC Statements can not accept parameters.

Syntax of Statement

		Statement statement = null;
		Connection connection = null;
		try {


		} catch (ClassNotFoundException e) {

		try {

			connection = DriverManager.getConnection(
					"jdbc:oracle:thin:@localhost:1521:" + dbName, userName,

		} catch (SQLException e) {


				statement = connection.createStatement();

				statement.execute(<Static Query>);


Prepared Statement

PreparedStatement extends Statement Interface to provide extra feature. It(PreparedStatement) is useful when firing the same SQL statement is required. PreparedStatement Interface accepts input parameter at runtime. PreparedStatement Objects are percompiled hence there execution is faster.

Syntax of PreparedStatement


		String inserRecordQuery= "insert into JBT values('beginne','Hibernate')";
		PreparedStatement  preparedStatement = null;
		Connection connection = null;


				preparedStatement = connection.prepareStatement(inserRecordQuery);




CallableStatement extends PreparedStatement Interface to provide more feature then PreparedStatement. It is used when database Stored Procedure needs to be invoked.

5 thoughts

  1. not that much great but good content
    but it should be specify with some diagram and internal things then it will more helpfulL for beginner

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top Search