What is the difference between store procedures and prepared statement?

Questions by radhap

Showing Answers 1 - 5 of 5 Answers

Stored procedure is serious of sql statement which treated as single transaction i.e either whole Tx has to commit or rollback where as Prepared statement is precomputed (Single) sql statement ,it will compile for first time execution and from the next time onwards it will simply substitute the values into prepared statement

Regards,
Ramesh Sukka

  Was this answer useful?  Yes

A stored procedure is saved in the database and may be called from any program that is connected to the database if the user has access rights.

The prepared statement will be part of a java class it is accessible as per the permissions set in the class

  Was this answer useful?  Yes

  1. Use PreparedStatement when you execute the same statement more than once.
  2. Use CallableStatement(stored procedure) when you want result from multiple and complex statements for a single request.

  Was this answer useful?  Yes

Generally procedure and functions are written in PL/SQL code and it will reside in databases.

When we develop some application in Java using JDBC to deal with specific databases for specific purpose like some complex type of operations are require for dealing with numerous data like using triggers or cursors and also for performance reason then generally we need the help of
callable statement to deal with procedure or a function.


N.B: Using callable statement to call procedure or function deal with databases make the application database oriented which is a
demerit for developing code taking help of procedure. But for performance reason procedure is much faster then using
prepared statement.


On the other hand in case of using prepared statement for making 1st Request from JDBC,
the Query Object which is passed to the database by the help of prepared
statement object is parsed by database engine only once for executing 1st Statement but for subsequent requests for different
values which is passes as a Query String using same SQL command


D.B Engine never check the entire Statement again and again, Its only take the
responsibility to check weather passed values are appropriate or not. So its better option for us if performance is the reason or we need specific database help for manipulation complex data go for
callable statement. Other wise prepared statement is right choice for us.

  Was this answer useful?  Yes

To be straightforward, we can only compare two things when they are in the same scope/domain. This question says to differentiate b/w SPs and prepared statements isn't valid.

Stored Procs are persistent objects at the database side when prepared statements are objects in jvm only and can't compare these two !!!


Thanks,
Vinay

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions