Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC queries or stored procedure

 
anish jain
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If there is a simple select or update statements needs to be fired then which one is better
1) write a simple JDBC query or
2) write a stored procedure for that

I am a bit confused between these two...which one will yield better performance

Also on what basis we should select if we should go for simple JDBC queries(Statement/PreparedStatement) or Strored procedure(CallableStatement)..

 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use stored procs unless there's a need for them. Anything that can be handled in a single SQL statement is not a good candidate for stored procs.
 
anish jain
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Don't use stored procs unless there's a need for them. Anything that can be handled in a single SQL statement is not a good candidate for stored procs.


do you mean to say the performance of calling a single SQL statement will be better than calling a stored procs?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, there are other reasons than performance to prefer one over the other. If there is a performance difference between the two it's likely to be too small to measure.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34672
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anish jain wrote:Also on what basis we should select if we should go for simple JDBC queries(Statement/PreparedStatement) or Strored procedure(CallableStatement)..

QA big downside to a stored procedure is you have to keep it in sync with the version of your code you have deployed. For a simple SQL statement, this downside is not offset by any upside.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic