• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

prepared statement Vs Stored procedures

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Skool. Stay in. Smartness. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic