Using PreparedStatement w/ Oracle

Using PreparedStatement w/ Oracle

Post by 15.. » Fri, 25 Aug 2000 04:00:00



Hi,
I'm writing a java application that uses an oracle
database extensively. (I'm using classes111.jar -
oracle jdbc driver to connect to the db). Since
the application has many queries that are used
repeatedly, I decided to use prepareStatement
method of Connection to prepare the query and
later pass the parameters in every iteration. Most
of these queries are select statements. The
parameters are String datatypes. This is where I
hit the problem, I guess.
Oracle does not allow us to use double quotes to
escape literals; allows only single qoutes.
Checked using getIdentifierQuoteString of
Connection's getMetaData, this driver uses double
quotes to escape. Is there any way to change this
meta data?
If I prepare the statement without any String
datatypes but with other types such as integer,
the query executes normally. Likewise, without
using prepareStatement, if I use normal Statement,
that works too.
Any help on this is highly appreciated.
thanks,
anand

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

Using PreparedStatement w/ Oracle

Post by Erik van Rood » Fri, 25 Aug 2000 04:00:00



> I decided to use prepareStatement
> method of Connection to prepare the query and
> later pass the parameters in every iteration. Most
> of these queries are select statements. The
> parameters are String datatypes. This is where I
> hit the problem, I guess.
> Oracle does not allow us to use double quotes to
> escape literals; allows only single qoutes.

  It sounds like you're using placeholder, yet you seem
to describe a problem that occurs when you don't
use placeholders. Could you post a _small_ code fragment
showing exactly what you're doing?

Erik

 
 
 

1. JDBC Oracle driver PreparedStatement.setTimestamp() using a Calendar object

Hi,

The JDBC 2.0 spec says that in a JDBC driver,  the method
PreparedStatement.setTimestamp( int parameterIndex,
java.sql.Timestamp ts, java.util.cal cal)
uses the passed-in cal object to adjust the timestamp only if the
underlying
database "does not store time zone information."
Presumeably,  if the database DOES store time zone information,
the cal object is ignored.

From what I can tell,   Oracle's DATE datatype does not store
time zone information,  and the OCI manuals talk a bit about writing
your applications carefully if they cross time zones (they tell you to
modify timestamps appropriately,  I think).

So would the proper thing to do in an Oracle JDBC driver be to
unconditionally modify a copy of the timestamp based on the
time zone of the passed-in cal object,  and store this in the
database (and doing the reverse modification for getTimestamp)?
Sounds like it to me.

Or does this behavior vary with different versions of the Oracle
server,  and do I therefore need to somehow query the database
to see if it has stored time zone information.  I'm unclear on
this part of the JDBC spec.

Thanks for any info/opinions.

-Marc

2. Re-opening a database

3. PreparedStatement using Oracle thin JDBC drivers

4. Query

5. Performance problem in using preparedStatement with mssqlserver driver

6. How to detect whether this is the first instance of the same MDB file? (Access 97)

7. creating a view using a preparedStatement and JDBC

8. Updating MDAC 2.1 to 2.5 in SQL Server 6.5

9. Using PreparedStatements with Merant SequeLink Driver

10. Using PreparedStatements for IN(...) clause

11. Preprocess strings without using PreparedStatement?

12. Updating multiple tables using JDBC PreparedStatement?