File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes How Does PreparedStatement Work internally Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "How Does PreparedStatement Work internally" Watch "How Does PreparedStatement Work internally" New topic

How Does PreparedStatement Work internally

vikram hegde

Joined: Sep 07, 2005
Posts: 18
Hi Java Pals,
Can any explain exactly, how PreparedStatemet Works? Any how excatly it makes difference in preformace compared to its base class Statement Class?

I request people to explain the internal aspects of working, I found only its syntax and usage on sites but no where i found its internal working. It will be helpful to all, if you give citation to refer.

Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
This question cannot really be answered because it depends on the driver.

There are essentially two ways in which it works.

One: The driver parses your query and identifies parameters. When you set the parameters the driver stores them and when you execute the driver builds the query from it's parsed bits and the bound parameters.

Two : The driver sends the query to the database where it is parsed (and perhaps a query plan is compiled) and a handle of some sort is returned to the driver. The driver then passes along the setXXX method calls and execute calls to the database directly.

And there can of course be variations of either. Like I said it depends on the database and driver. If this does not satisfy you then you can consult the source for one of the open source drivers like Jtds or the MySQL driver.
I agree. Here's the link:
subject: How Does PreparedStatement Work internally
It's not a secret anymore!