Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

prepared statement Vs Stored procedures

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Whats the diffrenece between Stored procedure and prepared statements
hari
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can think of a stored procedure as a method that exists within a db. i.e. code that lives in your db that you can execute. The language that they are written in (SPL) usually depends on the db vendor. For example, the syntax of an Oracle sp is different than an Informix sp. The benefits are: They execute quickly because they are an integral part of the db and are therefore optimized; They make it easy to encapsulate multiple queries/updates into one procedure.
PreparedStatements are part of the JDBC spec and are used to execute ANY kind of a statement against a db. Commonly, they are used to execute a "SELECT" or "UPDATE" statement, but they can even be used to execute a stored procedure! (although CallableStatements are better for executing stored procedures). When you call connection.prepareStatement(SQL), you are basically saying "I intend to execute this statement against this connection". They are very useful if you are executing the same statement multiple times, just with different parameters. Since you only "prepare" the statement once and then just change the input params as needed, the db has to check the sytax, build the query plan, etc., only once.
I think I went too far. To recap...
A stored procedure is compiled, db-specific code that resides within a db.
A PreparedStatement is just an efficient way in Java to execute any kind of an SQL statement.
 
She'll be back. I'm just gonna wait here. With this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic