• 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 ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
  • salvin francis
  • Piet Souris

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
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.
Make yourself as serene as a flower, as a tree. And on wednesdays, as serene as this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!