Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
vs
statement
prepared statement

Statement vs. prepared statement in Java

Educative Answers Team

The statement and prepared statement interfaces in Java enable us to use SQL commands to send and retrieve data.

svg viewer
svg viewer
  • Statement is used to call normal SQL queries.
  • Prepared statement is used to call parametrized or dynamic SQL queries.
Statement stm = conn.createStatement()
PreparedStatement stm = conn.prepareStatement( String Obj )
  • In this interface, only SQL queries without parameters can be passed.
  • In this interface, parameters can be passed at a run time.
  • This interface is preferred when a SQL command needs to be executed once. It is primarily​ used for DDL statements like CREATE, ALTER, etc.
  • This interface is preferred for SQL commands that need to be executed multiple times.
  • The performance of this interface is a bit low.
  • This interface performs​ far better than the normal statement.

RELATED TAGS

java
vs
statement
prepared statement
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring