aspose file tools*
The moose likes JDBC and the fly likes JDBC queries or stored procedure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC queries or stored procedure" Watch "JDBC queries or stored procedure" New topic
Author

JDBC queries or stored procedure

anish jain
Ranch Hand

Joined: Feb 03, 2010
Posts: 129
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
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
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.


Ping & DNS - my free Android networking tools app
anish jain
Ranch Hand

Joined: Feb 03, 2010
Posts: 129
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
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
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

Joined: May 26, 2003
Posts: 30925
    
158

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JDBC queries or stored procedure