Oracle Thin JDBC Driver: problems streaming long/long raw in parameters

Oracle Thin JDBC Driver: problems streaming long/long raw in parameters

Post by Michael Seyfrie » Thu, 20 Nov 1997 04:00:00



This is a multi-part message in MIME format.
--------------460810D73136F82438059B26
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hello,

there is a bug in the Oracle Thin JDBC Driver 7.3.4: Streaming of
LONG/LONG RAW in parameters may cause exceptions.
I attached a little Java program to this message which reproduces the
bug and produces the following output:

J:\projects\Test\src\Test>java BLOBBug2
1 rows with data size=512bytes inserted at point 1.1
java.sql.SQLException: ORA-01483: invalid length for DATE or NUMBER bind
variable

        at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:184)
        at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:631)
        at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1206)

        at
oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:649)
        at
oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:761)

        at
oracle.jdbc.driver.OracleStatement.doExecuteWithBatch(OracleStatement.java:803)

        at
oracle.jdbc.driver.OracleStatement.doExecute(OracleStatement.java:1145)
        at
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1178)

        at
oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:94)

        at BLOBBug2.main(BLOBBug2.java:67)
1 rows with data size=512bytes inserted at point 2.1
java.sql.SQLException: ORA-01483: invalid length for DATE or NUMBER bind
variable

        at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:184)
        at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:631)
        at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1206)

        at
oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:649)
        at
oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:761)

        at
oracle.jdbc.driver.OracleStatement.doExecuteWithBatch(OracleStatement.java:803)

        at
oracle.jdbc.driver.OracleStatement.doExecute(OracleStatement.java:1145)
        at
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1178)

        at
oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:94)

        at BLOBBug2.main(BLOBBug2.java:93)

The same program works fine with the OCI7 driver.

Michael Seyfried
--------------------------------------------------------------------
BLITZ Internet Service GmbH, Nebingerhof 5, D-96047 Bamberg, Germany
Tel: +49/951/9685163,   Fax: +49/951/9685164,   http://www.blitz.net

--------------460810D73136F82438059B26
Content-Type: java/*; name="BLOBBug2.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="BLOBBug2.java"

import java.sql.*;
import java.io.*;

class BLOBBug2
{
  static final int size = 512;

  public static void main (String args [])
       throws SQLException, ClassNotFoundException, IOException
  {
    Class.forName ("oracle.jdbc.driver.OracleDriver");

        // replace connection parameters for your database
        // the error does only occur using jdbc:oracle:thin, jdbc:oracle:oci7 works correct.
    Connection conn =
                // A. works fine with this connection:

                // B. throws exceptions with this connection:

    conn.setAutoCommit (false);

    Statement stmt = conn.createStatement ();

        // Create file with size bytes of data
        {
                FileOutputStream os = new FileOutputStream ("data.dat");

                int c;
                byte buf [] = new byte [size];
                os.write (buf);
                os.close ();
        }

    // Create the example table
    try
    {
      stmt.execute ("drop table streamexample1");
      stmt.execute ("drop table streamexample2");
    }
    catch (SQLException e)
    {
    }
    stmt.execute ("create table streamexample1 (ID number (10), DATA long raw)");
    stmt.execute ("create table streamexample2 (ID number (10), DATA long)");

    // Insert 1.1 => works fine
    File file = new File ("data.dat");
    InputStream is = new FileInputStream (file);
    PreparedStatement pstmt = conn.prepareStatement ("insert into streamexample1 (id, data) values (?, ?)");
        try {
                pstmt.setInt (1, 1);
                pstmt.setBinaryStream (2, is, (int)file.length ());
                System.out.println (pstmt.executeUpdate () + " rows with data size=" + file.length () + "bytes inserted at point 1.1");
        } catch (SQLException e) {
                e.printStackTrace ();
        } finally {
                is.close ();
        }

    // Insert 1.2 => throws an exception
    is = new FileInputStream (file);
    pstmt = conn.prepareStatement ("insert into streamexample1 (data, id) values (?, ?)");
        try {
                pstmt.setBinaryStream (1, is, (int)file.length ());
                pstmt.setInt (2, 2);
                System.out.println (pstmt.executeUpdate () + " rows with data size=" + file.length () + "bytes inserted at point 1.2");
        } catch (SQLException e) {
                e.printStackTrace ();
        } finally {
                is.close ();
        }

    // Insert 2.1 => works fine
    is = new FileInputStream (file);
    pstmt = conn.prepareStatement ("insert into streamexample1 (id, data) values (?, ?)");
        try {
                pstmt.setInt (1, 1);
                pstmt.setBinaryStream (2, is, (int)file.length ());
                System.out.println (pstmt.executeUpdate () + " rows with data size=" + file.length () + "bytes inserted at point 2.1");
        } catch (SQLException e) {
                e.printStackTrace ();
        } finally {
                is.close ();
        }

    // Insert 2.2 => throws an exception
    is = new FileInputStream (file);
    pstmt = conn.prepareStatement ("insert into streamexample1 (data, id) values (?, ?)");
        try {
                pstmt.setBinaryStream (1, is, (int)file.length ());
                pstmt.setInt (2, 2);
                System.out.println (pstmt.executeUpdate () + " rows with data size=" + file.length () + "bytes inserted at point 2.2");
        } catch (SQLException e) {
                e.printStackTrace ();
        } finally {
                is.close ();
        }
  }

Quote:}

--------------460810D73136F82438059B26--