• 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

Statement & PreparedStatement difference?

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All,
What is the differences between those two objects,please sample codes to clear up any confusion.
Thanks.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know that sample code would really clear anything up as to what the difference is between the 2.
Basically, when you use a PreparedStatement, the SQL statement is preprocessed before being sent to the DB.
If you just us a Statement the SQL is sent straight to the DB without ever being processed.
The reason this can be a problem is because of special characters. So if you used a contraction like don't won't can't isn't as data inside your SQL, the ' is a special SQL character that needs to be escaped before it hits the DB. This is what PreparedStatement will do for you.
Personally, I almost always use a PreparedStatement when inserting and updating data in the DB not only because of the reasons mentioned above, but because I like the syntax and how you formulate your query better. It looks neater, and I am a code neat freak.
 
carl varola
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when you say "SQL statement is preprocessed " when u use preparedStatement,preprocessed by what?your application?your database engine?plz more info.
Thanks
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your JDBC Driver actually does the preprocessing.
You have to understand that a DB REALLY doesn't understand SQL. When you submit SQL to a database, it actually goes through a preprocessor that converts the SQL into the language that the DB can understand and use. This processing typically happens on the DB itself.
 
carl varola
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks........i will read more about it and probably i will come up with more questions............thanks.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic