• 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 statements vs. statement.execute

 
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
does anybody have a link to some document comparing where and when to use prepared statements?
Can anyone say what are the main points where prepared statements are better?
I've got an app where I haven't used any prepared statments at all and I think I need to implement a better framework for my database access.
Currently every database op has the SQL statement in two strings, one for Oracle and one for mySQL and the appropriate string is chosen depending on the config.
I don't really like this because I always did apps where I can use stored procedures and I don't need any SQL in my Java code.
If it turns into a big app, and we get a seperate database administrator, then he'll have to start diving into the java source files whenever he changes the database. Are there any other frameworks I can use?

Thanks!
Adam
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know prepared statements are precompiled statements, hence it's already parsed. It also makes it easy to execute the same statement while only changing the parameters to the statement. It also tekes care of formatting, special characters, etc. You can check out the JDBC tutorial at Sun's site for more details.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also think you need to use prepared statement when you are calling a stored procedure. But in Oracle I know I can run a query like
select stored_procedure(arguments) from dual
and run them in the statement.execute.
Just some 2 cents, for whatever it's worth
Mark
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might find this link very relevant.
Prepared Statements vs Statement
 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the tips, folks (especially the O'Reillys link).
So what about the other issue, about where to write the actual SQL? Does everybody here do it in the business objects / layer, or has anybody ever implemented a seperate data layer which does the call to the database and returns marshalled data?
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
we use a data access layer. they contain all our db access code. These are commonly used to centralize your db code. other objects call methods in the data access object.
 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just replied to your other message with the same link http://martinfowler.com/ and he talks about keeping SQL in an XML file and sucking it all in at startup.
 
ice is for people that are not already cool. Chill with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic