Query in Prepared statements caching  
Author Message
mailkhurana





PostPosted: 2004-11-15 1:01:00 Top

java-programmer, Query in Prepared statements caching Hii ,
I am using Db2 V 7.1 on ZOS
I have the following Java Code
query.append("insert into ");
query.append(schemaName+".EMAIL_DATA ");
query.append("(EMAIL_NBR, DT_FIRST_SENT,SUBJECT
,EMAIL_ADDR,EMAIL_DTL,ER_NBR, DT_CREATED,DT_LAST_SENT)
values(?,?,?,?,?,?,?,?) ");
prepStmt=connect.prepareStatement(query.toString());

I want to know whether the above query would be cached in the data
base server since apart from the using the standard ? to give various
parameters at runtime , I am also picking up the schema at runtime and
not hardcoding.
But obviously the schema name will remain the same for all the calls
to the DB.
I donno whether due to the usage of a Java Variable in the query at
runtime whether this will be cached or not ?
Can some one please throw some light on it ?
Regarda,
-Neeraj
 
Matt Emmerton





PostPosted: 2004-11-15 10:01:00 Top

java-programmer >> Query in Prepared statements caching
"Neeraj" <email***@***.com> wrote in message
news:email***@***.com...
> Hii ,
> I am using Db2 V 7.1 on ZOS
> I have the following Java Code
> query.append("insert into ");
> query.append(schemaName+".EMAIL_DATA ");
> query.append("(EMAIL_NBR, DT_FIRST_SENT,SUBJECT
> ,EMAIL_ADDR,EMAIL_DTL,ER_NBR, DT_CREATED,DT_LAST_SENT)
> values(?,?,?,?,?,?,?,?) ");
> prepStmt=connect.prepareStatement(query.toString());
>
> I want to know whether the above query would be cached in the data
> base server since apart from the using the standard ? to give various
> parameters at runtime , I am also picking up the schema at runtime and
> not hardcoding.
> But obviously the schema name will remain the same for all the calls
> to the DB.
> I donno whether due to the usage of a Java Variable in the query at
> runtime whether this will be cached or not ?
> Can some one please throw some light on it ?

From DB2's perspective, the exact statement (query string) given to
prepareStatement() will be cached.
DB2 doesn't know that the statement is built up of some string values and
the "dynamically" determined schema name.
Thus, if you run this multiple times without changing the schema, DB2 will
always reuse the cached version.


 
shenanwei





PostPosted: 2004-11-16 1:06:00 Top

java-programmer >> Query in Prepared statements caching email***@***.com (Neeraj) wrote in message news:<email***@***.com>...
> Hii ,
> I am using Db2 V 7.1 on ZOS
> I have the following Java Code
> query.append("insert into ");
> query.append(schemaName+".EMAIL_DATA ");
> query.append("(EMAIL_NBR, DT_FIRST_SENT,SUBJECT
> ,EMAIL_ADDR,EMAIL_DTL,ER_NBR, DT_CREATED,DT_LAST_SENT)
> values(?,?,?,?,?,?,?,?) ");
> prepStmt=connect.prepareStatement(query.toString());
>
> I want to know whether the above query would be cached in the data
> base server since apart from the using the standard ? to give various
> parameters at runtime , I am also picking up the schema at runtime and
> not hardcoding.
> But obviously the schema name will remain the same for all the calls
> to the DB.
> I donno whether due to the usage of a Java Variable in the query at
> runtime whether this will be cached or not ?
> Can some one please throw some light on it ?
> Regarda,
> -Neeraj

DB2 has package cache will do this job for y.