Return-Path: Delivered-To: apmail-db-derby-dev-archive@www.apache.org Received: (qmail 82387 invoked from network); 8 Sep 2005 08:58:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 8 Sep 2005 08:58:46 -0000 Received: (qmail 27057 invoked by uid 500); 8 Sep 2005 08:58:45 -0000 Delivered-To: apmail-db-derby-dev-archive@db.apache.org Received: (qmail 27018 invoked by uid 500); 8 Sep 2005 08:58:44 -0000 Mailing-List: contact derby-dev-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Development" Delivered-To: mailing list derby-dev@db.apache.org Received: (qmail 27005 invoked by uid 99); 8 Sep 2005 08:58:44 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=SPF_FAIL X-Spam-Check-By: apache.org Received: from [192.87.106.226] (HELO ajax.apache.org) (192.87.106.226) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Sep 2005 01:58:43 -0700 Received: from ajax.apache.org (ajax.apache.org [127.0.0.1]) by ajax.apache.org (Postfix) with ESMTP id 1745B133 for ; Thu, 8 Sep 2005 10:58:42 +0200 (CEST) Message-ID: <471690487.1126169922093.JavaMail.jira@ajax.apache.org> Date: Thu, 8 Sep 2005 10:58:42 +0200 (CEST) From: "Fernanda Pizzorno (JIRA)" To: derby-dev@db.apache.org Subject: [jira] Updated: (DERBY-463) Successive writes to a java.sql.Blob.setBinaryStream(long) seem to reset the file pointer In-Reply-To: <859414957.1121432109873.JavaMail.jira@ajax.apache.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N [ http://issues.apache.org/jira/browse/DERBY-463?page=all ] Fernanda Pizzorno updated DERBY-463: ------------------------------------ Attachment: DERBY-463.diff DERBY-463.stat - The test blobSetBinaryStreams.java was only testing the write(byte[], int, int) method for blobs. I have extendedit so that it would use both write(byte[], int, int) and write(int) for both blobs and clobs. Since it was not a blob specific test, I have renamed it to lobStreams.java. - Similar problems as the one fixed in the previous patch (the offset was not being incremented) existed in write(int) (for clobs and blobs) and write(byte[], int, int) (for clobs). These problems have now been fixed. - I have run derbyall successfully, except for store/encryptionKey.sql that failed, but I don't think it was related to my patch. > Successive writes to a java.sql.Blob.setBinaryStream(long) seem to reset the file pointer > ----------------------------------------------------------------------------------------- > > Key: DERBY-463 > URL: http://issues.apache.org/jira/browse/DERBY-463 > Project: Derby > Type: Bug > Components: JDBC > Versions: 10.0.2.1 > Environment: Sun java full version "1.4.2_05-b04" > Linux x86 > Derby is run in network server mode > Reporter: Laurenz Albe > Assignee: Fernanda Pizzorno > Fix For: 10.2.0.0 > Attachments: DERBY-463.diff, DERBY-463.diff, DERBY-463.stat, DERBY-463.stat > > I have a table > PEOPLE(SEQ_ID INT NOT NULL PRIMARY KEY, PICTURE BLOB). > A row is inserted; both values are not NULL. > From inside a JDBC program, I select the Blob for update. > I then get the Blob output stream with a call to > Blob.setBinaryStream(long) > To this stream I write several times with > OutputStream.write(byte[], int, int) > I close the stream, update the selected row with the new Blob and commit. > The new value of the Blob now is exactly the value of the last content of the byte[], > and it is like the previous calls to write() have never taken place, or as if the file pointer > of the output stream has been reset between the calls. > A sample program follows; the size of the input file "picture.jpg" is 23237, the length > of the Blob after the program has run is 23237 % 1024 = 709 > ------------ sample program ------------- > import java.sql.*; > class TestApp { > private TestApp() {} > public static void main(String[] args) > throws ClassNotFoundException, SQLException, java.io.IOException { > // try to load JDBC driver > Class.forName("com.ibm.db2.jcc.DB2Driver"); > // open the input file > java.io.InputStream instream = new java.io.FileInputStream("picture.jpg"); > // login to database > Connection conn = DriverManager.getConnection( > "jdbc:derby:net://dbtuxe/testdb", "laurenz", "apassword"); > conn.setAutoCommit(false); > // select Blob for update > PreparedStatement stmt = conn.prepareStatement( > "SELECT PICTURE FROM PEOPLE WHERE SEQ_ID=? FOR UPDATE OF PICTURE"); > stmt.setInt(1, 1); > ResultSet rs = stmt.executeQuery(); > // get Blob output stream > rs.next(); > Blob blob = rs.getBlob(1); > java.io.OutputStream outstream = blob.setBinaryStream(1l); > // copy the input file to the Blob in chunks of 1K > byte[] buf = new byte[1024]; > int count; > while (-1 != (count = instream.read(buf))) { > outstream.write(buf, 0, count); > System.out.println("Written " + count + " bytes to Blob"); > } > // close streams > instream.close(); > outstream.close(); > // update Blob with new value > String cursor = rs.getCursorName(); > PreparedStatement stmt2 = conn.prepareStatement( > "UPDATE PEOPLE SET PICTURE=? WHERE CURRENT OF " + cursor); > stmt2.setBlob(1, blob); > stmt2.executeUpdate(); > // clean up > stmt2.close(); > stmt.close(); > conn.commit(); > conn.close(); > } > } -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira