If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > paramterised queries

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-04-06, 12:23
AnilKale AnilKale is offline
Registered User
 
Join Date: Feb 2005
Posts: 118
paramterised queries

Hi All !

I mentioned the following to one of the java developer:
Use parameterized queries.
The key performance benefit of parameterized queries is that the optimizer can formulate an access path that can be reused over repeated executions of the statement. This can accrue a large performance gain for the program as compared to issuing a completely new SQL statement every time a new value is required in a WHERE clause. (quoted from the db2 manual)

The java developer replied that all java sql statements are parameterized queries. I am not a java person. Could someone validate this statement for me - that all java sql statements are parameterized queries.

I am trying to identify if I need to include the 'Use parameterized queries' statement in the best practices document (specifically sql best practices for java developers)

Thanks
Anil
Reply With Quote
  #2 (permalink)  
Old 04-04-06, 12:43
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
No, all java sql statements are not parameterized. The java.sql.Statement does not take parameters. The java.sql.PreparedStatement and the CallableStatement do.

Andy
Reply With Quote
  #3 (permalink)  
Old 04-05-06, 03:35
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
If you run a snapshot for dynamic SQL, then you will see the queries. If the predicates have question marks (?) instead of literals, then it is parameterized.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #4 (permalink)  
Old 04-05-06, 05:15
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
http://publib.boulder.ibm.com/infoce...plespjava1.htm
This is a very simple example of a parameterized SQL in Java program ..
Get an example of a program which the Developers claim to be using parameterised SQL ...
and check for keywords like setString (or any of the setxxx type constructs detailed in table 57 in http://publib.boulder.ibm.com/infoce...d/rjvjdapi.htm)
The general constuct of the program will be as follows :
a) Assign a statement text with a parameter marker to a string variable
b) Prepare the sql statement using the above string variable and assign it to a statement object
c) Use setString,setInt etc on the statement object and set the parameter values of the SQL
d) Execute the statement object using executeQuery (select stmts) or executeUpdate (IUD stmts)
e) Repeat c and d as many times as needed [ because the sql statement is already prepared ]

HTH

Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On