Don't do DDL with PreparedStatement with Oracle!

This is a discussion on Don't do DDL with PreparedStatement with Oracle! within the JDBC JAVA forums in Framework and Interface Programming category; Hi all. I found a customer who wanted to repeat the SQL "TRUNCATE TABLE MY_TABLE", so they did: ps = c.prepareStatement("TRUNCATE TABLE THEIR_TABLE"); This statement *worked fine* the first time they executed it, but fascinatingly, every subsequent execution of that statement *silently failed, doing *nothing*! The driver got the expected response packet from the DBMS, but Oracle did nothing. The customer could even continue to execute this statement, seemingly successfully, after they completely dropped the table! The case was complicated because their code actually created, executed, and closed the statement each time, but because the customer was using a connection ...

Go Back   Application Development Forum > Framework and Interface Programming > JDBC JAVA

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 02-13-2008, 06:14 PM
joeNOSPAM@BEA.com
Guest
 
Default Don't do DDL with PreparedStatement with Oracle!

Hi all.

I found a customer who wanted to repeat the SQL "TRUNCATE TABLE
MY_TABLE",
so they did:

ps = c.prepareStatement("TRUNCATE TABLE THEIR_TABLE");


This statement *worked fine* the first time they executed it, but
fascinatingly,
every subsequent execution of that statement *silently failed, doing
*nothing*!
The driver got the expected response packet from the DBMS, but Oracle
did
nothing. The customer could even continue to execute this statement,
seemingly
successfully, after they completely dropped the table!
The case was complicated because their code actually created,
executed,
and closed the statement each time, but because the customer was using
a
connection pooling system (like BEA's or Oracle's own JDBC driver),
that will
transparently cache and re-use PreparedStatements (a big performance
feature),
the application would get the same statement under the covers, and
start
getting the odd NO-OP behavior.
Oracle's driver and our pooling are both unable to do anything about
this,
when the SQL is created at runtime by the customer, and this DBMS bug
would force the non-caching of statements for anyone sending DDL, like
that. To reiterate, this is an Oracle DBMS bug. It can be reproduced
with
a simple JDBC client or an OCI+C program, but not SQL-PLUS because
SQL-PLUS never prepares statements....

FYI,
Joe Weinstein at BEA Systems
Reply With Quote
  #2  
Old 02-13-2008, 06:43 PM
joeNOSPAM@BEA.com
Guest
 
Default Re: Don't do DDL with PreparedStatement with Oracle!

(I don't know why the original was so badly formatted)
Hi all.

I found a customer who wanted to repeat the SQL "TRUNCATE TABLE
MY_TABLE", so they did:

ps = c.prepareStatement("TRUNCATE TABLE THEIR_TABLE");

This statement *worked fine* the first time they executed it, but
fascinatingly, every subsequent execution of that statement
*silently failed, doing *nothing*! The driver got the expected
response packet from the DBMS, but Oracle did nothing. The
customer could even continue to execute this statement, seemingly
successfully, after they completely dropped the table!
The case was complicated because their code actually created,
executed, and closed the statement each time, but because the
customer was using a connection pooling system (like BEA's or
Oracle's own JDBC driver), that will transparently cache and
re-use PreparedStatements (a big performance feature), the
application would get the same statement under the covers, and
start getting the odd NO-OP behavior.
Oracle's driver and our pooling are both unable to do anything
about this, when the SQL is created at runtime by the customer,
and this DBMS bug would force the non-caching of statements for
anyone sending DDL, like that. To reiterate, this is an Oracle
DBMS bug. It can be reproduced with a simple JDBC client or an
OCI+C program, but not SQL-PLUS because SQL-PLUS never prepares
statements....

FYI,
Joe Weinstein at BEA Systems

Reply With Quote
  #3  
Old 02-14-2008, 12:02 PM
kuassi.mensah@gmail.com
Guest
 
Default Re: Don't do DDL with PreparedStatement with Oracle!

On Feb 13, 3:43*pm, "joeNOS...@BEA.com" <joe.weinst...@gmail.com>
wrote:
> (I don't know why the original was so badly formatted)
> Hi all.
>
> I found a customer who wanted to repeat the SQL "TRUNCATE TABLE
> MY_TABLE", so they did:
>
> ps = c.prepareStatement("TRUNCATE TABLE THEIR_TABLE");
>
> This statement *worked fine* the first time they executed it, but
> fascinatingly, every subsequent execution of that statement
> *silently failed, doing *nothing*! The driver got the expected
> response packet from the DBMS, but Oracle did nothing. The
> customer could even continue to execute this statement, seemingly
> successfully, after they completely dropped the table!
> * *The case was complicated because their code actually created,
> executed, and closed the statement each time, but because the
> customer was using a connection pooling system (like BEA's or
> Oracle's own JDBC driver), that will transparently cache and
> re-use PreparedStatements (a big performance feature), the
> application would get the same statement under the covers, and
> start getting the odd NO-OP behavior.
> * Oracle's driver and our pooling are both unable to do anything
> about this, when the SQL is created at runtime by the customer,
> and this DBMS bug would force the non-caching of statements for
> anyone sending DDL, like that. To reiterate, this is an Oracle
> DBMS bug. It can be reproduced with a simple JDBC client or an
> OCI+C program, but not SQL-PLUS because SQL-PLUS never prepares
> statements....
>
> FYI,
> Joe Weinstein at BEA Systems


It is documented that DDLs should be re-prepared however, I found out
that the OCI driver manages to avoid re-parsing of DDL, throug its
statement cache. The Oracle JDBC team will look into doing the same.

Kuassi
Oracle JDBC product managemenent
http://db360.blogspot.com

Reply With Quote
  #4  
Old 02-14-2008, 12:27 PM
joeNOSPAM@BEA.com
Guest
 
Default Re: Don't do DDL with PreparedStatement with Oracle!

On Feb 14, 9:02 am, "kuassi.men...@gmail.com"
<kuassi.men...@gmail.com> wrote:
> On Feb 13, 3:43 pm, "joeNOS...@BEA.com" <joe.weinst...@gmail.com>
> wrote:
>
>
>
> > (I don't know why the original was so badly formatted)
> > Hi all.

>
> > I found a customer who wanted to repeat the SQL "TRUNCATE TABLE
> > MY_TABLE", so they did:

>
> > ps = c.prepareStatement("TRUNCATE TABLE THEIR_TABLE");

>
> > This statement *worked fine* the first time they executed it, but
> > fascinatingly, every subsequent execution of that statement
> > *silently failed, doing *nothing*! The driver got the expected
> > response packet from the DBMS, but Oracle did nothing. The
> > customer could even continue to execute this statement, seemingly
> > successfully, after they completely dropped the table!
> > The case was complicated because their code actually created,
> > executed, and closed the statement each time, but because the
> > customer was using a connection pooling system (like BEA's or
> > Oracle's own JDBC driver), that will transparently cache and
> > re-use PreparedStatements (a big performance feature), the
> > application would get the same statement under the covers, and
> > start getting the odd NO-OP behavior.
> > Oracle's driver and our pooling are both unable to do anything
> > about this, when the SQL is created at runtime by the customer,
> > and this DBMS bug would force the non-caching of statements for
> > anyone sending DDL, like that. To reiterate, this is an Oracle
> > DBMS bug. It can be reproduced with a simple JDBC client or an
> > OCI+C program, but not SQL-PLUS because SQL-PLUS never prepares
> > statements....

>
> > FYI,
> > Joe Weinstein at BEA Systems

>
> It is documented that DDLs should be re-prepared however, I found out
> that the OCI driver manages to avoid re-parsing of DDL, throug its
> statement cache. The Oracle JDBC team will look into doing the same.
>
> Kuassi
> Oracle JDBC product managemenenthttp://db360.blogspot.com


Hi Kuassi! Thanks. I don't understand though... If I am correct,
the SQL "TRUNCATE TABLE MYTABLE" *needs* to be re-prepared, else
the DBMS will do nothing. Any client-side caching would simply
aggravate the problem, making a user's re-prepare get the same
now-unfunctional statement from the cache.
Joe
Reply With Quote
  #5  
Old 02-14-2008, 02:39 PM
kuassi.mensah@gmail.com
Guest
 
Default Re: Don't do DDL with PreparedStatement with Oracle!

On Feb 14, 9:27*am, "joeNOS...@BEA.com" <joe.weinst...@gmail.com>
wrote:
> On Feb 14, 9:02 am, "kuassi.men...@gmail.com"
>
>
>
>
>
> <kuassi.men...@gmail.com> wrote:
> > On Feb 13, 3:43 pm, "joeNOS...@BEA.com" <joe.weinst...@gmail.com>
> > wrote:

>
> > > (I don't know why the original was so badly formatted)
> > > Hi all.

>
> > > I found a customer who wanted to repeat the SQL "TRUNCATE TABLE
> > > MY_TABLE", so they did:

>
> > > ps = c.prepareStatement("TRUNCATE TABLE THEIR_TABLE");

>
> > > This statement *worked fine* the first time they executed it, but
> > > fascinatingly, every subsequent execution of that statement
> > > *silently failed, doing *nothing*! The driver got the expected
> > > response packet from the DBMS, but Oracle did nothing. The
> > > customer could even continue to execute this statement, seemingly
> > > successfully, after they completely dropped the table!
> > > * *The case was complicated because their code actually created,
> > > executed, and closed the statement each time, but because the
> > > customer was using a connection pooling system (like BEA's or
> > > Oracle's own JDBC driver), that will transparently cache and
> > > re-use PreparedStatements (a big performance feature), the
> > > application would get the same statement under the covers, and
> > > start getting the odd NO-OP behavior.
> > > * Oracle's driver and our pooling are both unable to do anything
> > > about this, when the SQL is created at runtime by the customer,
> > > and this DBMS bug would force the non-caching of statements for
> > > anyone sending DDL, like that. To reiterate, this is an Oracle
> > > DBMS bug. It can be reproduced with a simple JDBC client or an
> > > OCI+C program, but not SQL-PLUS because SQL-PLUS never prepares
> > > statements....

>
> > > FYI,
> > > Joe Weinstein at BEA Systems

>
> > It is documented that DDLs should be re-prepared however, I found out
> > that the OCI driver manages to avoid re-parsing of DDL, throug its
> > statement cache. The Oracle JDBC team will look into doing the same.

>
> > Kuassi
> > Oracle JDBC product managemenenthttp://db360.blogspot.com

>
> Hi Kuassi! Thanks. I don't understand though... If I am correct,
> the SQL "TRUNCATE TABLE MYTABLE" *needs* to be re-prepared, else
> the DBMS will do nothing. Any client-side caching would simply
> aggravate the problem, making a user's re-prepare get the same
> now-unfunctional statement from the cache.
> Joe- Hide quoted text -
>
> - Show quoted text -


Mea culpa; in fact OCI mark the DDL for re-parsing, which avoids the
no-op on subsequent execution.

Kuassi
Reply With Quote
  #6  
Old 02-14-2008, 03:01 PM
joeNOSPAM@BEA.com
Guest
 
Default Re: Don't do DDL with PreparedStatement with Oracle!

On Feb 14, 11:39 am, "kuassi.men...@gmail.com"
<kuassi.men...@gmail.com> wrote:
> On Feb 14, 9:27 am, "joeNOS...@BEA.com" <joe.weinst...@gmail.com>
> wrote:
>
>
>
> > On Feb 14, 9:02 am, "kuassi.men...@gmail.com"

>
> > <kuassi.men...@gmail.com> wrote:
> > > On Feb 13, 3:43 pm, "joeNOS...@BEA.com" <joe.weinst...@gmail.com>
> > > wrote:

>
> > > > (I don't know why the original was so badly formatted)
> > > > Hi all.

>
> > > > I found a customer who wanted to repeat the SQL "TRUNCATE TABLE
> > > > MY_TABLE", so they did:

>
> > > > ps = c.prepareStatement("TRUNCATE TABLE THEIR_TABLE");

>
> > > > This statement *worked fine* the first time they executed it, but
> > > > fascinatingly, every subsequent execution of that statement
> > > > *silently failed, doing *nothing*! The driver got the expected
> > > > response packet from the DBMS, but Oracle did nothing. The
> > > > customer could even continue to execute this statement, seemingly
> > > > successfully, after they completely dropped the table!
> > > > The case was complicated because their code actually created,
> > > > executed, and closed the statement each time, but because the
> > > > customer was using a connection pooling system (like BEA's or
> > > > Oracle's own JDBC driver), that will transparently cache and
> > > > re-use PreparedStatements (a big performance feature), the
> > > > application would get the same statement under the covers, and
> > > > start getting the odd NO-OP behavior.
> > > > Oracle's driver and our pooling are both unable to do anything
> > > > about this, when the SQL is created at runtime by the customer,
> > > > and this DBMS bug would force the non-caching of statements for
> > > > anyone sending DDL, like that. To reiterate, this is an Oracle
> > > > DBMS bug. It can be reproduced with a simple JDBC client or an
> > > > OCI+C program, but not SQL-PLUS because SQL-PLUS never prepares
> > > > statements....

>
> > > > FYI,
> > > > Joe Weinstein at BEA Systems

>
> > > It is documented that DDLs should be re-prepared however, I found out
> > > that the OCI driver manages to avoid re-parsing of DDL, throug its
> > > statement cache. The Oracle JDBC team will look into doing the same.

>
> > > Kuassi
> > > Oracle JDBC product managemenenthttp://db360.blogspot.com

>
> > Hi Kuassi! Thanks. I don't understand though... If I am correct,
> > the SQL "TRUNCATE TABLE MYTABLE" *needs* to be re-prepared, else
> > the DBMS will do nothing. Any client-side caching would simply
> > aggravate the problem, making a user's re-prepare get the same
> > now-unfunctional statement from the cache.
> > Joe- Hide quoted text -

>
> > - Show quoted text -

>
> Mea culpa; in fact OCI mark the DDL for re-parsing, which avoids the
> no-op on subsequent execution.
>
> Kuassi


Interesting... So how does OCI *know* it's DDL? Or is OCI marking
*every* statement for re-parse? Wouldn't that be a big performance
regression, asking the DBMS to re-parse everything, even the DML
statements that don't need it?
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 03:42 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.