Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 46171 invoked from network); 19 Feb 2005 18:25:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 19 Feb 2005 18:25:04 -0000 Received: (qmail 2927 invoked by uid 500); 19 Feb 2005 18:25:03 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 2903 invoked by uid 500); 19 Feb 2005 18:25:03 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 2890 invoked by uid 99); 19 Feb 2005 18:25:02 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from brmea-mail-4.Sun.COM (HELO brmea-mail-4.sun.com) (192.18.98.36) by apache.org (qpsmtpd/0.28) with ESMTP; Sat, 19 Feb 2005 10:25:01 -0800 Received: from fe3.sun.com (fe3.Sun.COM [192.18.108.80] (may be forged)) by brmea-mail-4.sun.com (8.12.10/8.12.9) with ESMTP id j1JIOxKw000355 for ; Sat, 19 Feb 2005 11:24:59 -0700 (MST) Received: from conversion-daemon.fe3.sun.com by fe3.sun.com (Sun Java System Messaging Server 6.1 HotFix 0.02 (built Aug 25 2004)) id <0IC600K018HM6100@fe3.sun.com> (original mail from Craig.Russell@Sun.COM) for derby-user@db.apache.org; Sat, 19 Feb 2005 11:24:58 -0700 (MST) Received: from [192.168.0.10] ([24.6.172.77]) by fe3.sun.com (Sun Java System Messaging Server 6.1 HotFix 0.02 (built Aug 25 2004)) with ESMTPSA id <0IC600JU48HLFW03@fe3.sun.com> for derby-user@db.apache.org; Sat, 19 Feb 2005 11:24:58 -0700 (MST) Date: Sat, 19 Feb 2005 10:24:52 -0800 From: Craig Russell Subject: Re: How to invoke methods of Blob interface In-reply-to: <20050219053747.96276.qmail@web31101.mail.mud.yahoo.com> To: Derby Discussion Message-id: MIME-version: 1.0 X-Mailer: Apple Mail (2.619.2) Content-type: multipart/signed; protocol="application/pkcs7-signature"; boundary=Apple-Mail-131--466209605; micalg=sha1 References: <20050219053747.96276.qmail@web31101.mail.mud.yahoo.com> X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N --Apple-Mail-131--466209605 Content-Type: multipart/alternative; boundary=Apple-Mail-130--466210126 --Apple-Mail-130--466210126 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=ISO-8859-1; format=flowed Hi Mithun, I think that Barnet was talking about using the PreparedStatement=20 interface and avoiding the Blob interface entirely. That is, PreparedStatement ps =3D conn.PrepareStatement("insert into EMPLOYEE(ID,=20= IMAGE) values(?,?)"); ps.setInt(1, id); byte[] b =3D ... // serialize arbitrary object to byte[] ByteArrayInputStream ins =3D new ByteArrayInputStream(b); ps.setBinaryStream(2, ins, b.length); int result =3D ps.executeUpdate(); You can use a similar technique on input, using the getBinaryStream=20 method of ResultSet. The binary stream methods of PreparedStatement and=20= ResultSet are highly portable across vendors. Craig On Feb 18, 2005, at 9:37 PM, Mithun Ruikar wrote: > Hello , > =A0 > Barnet Wagman replied me , to use setBinaryStream method of Blob=20 > interface. > But How can I instantiate Blob object , as it is interface and I dont=20= > know it's implemetation ? > =A0 > How I can get blob object to call setBinaryStream. > =A0 > that is : > ps.setBinaryStream(psParamIndex, ins, b.length); > from where you got this ps and what is the value of psParamIndex. > > thank you > > -- mithun > Barnet Wagman wrote: > I always serialize the object to a byte[]=A0 and then use=20 > setBinaryStream(), e.g. > > byte[] b =3D ... // serialize arbitrary object to byte[] > > ByteArrayInputStream ins =3D new ByteArrayInputStream(b); > ps.setBinaryStream(psParamIndex, ins, b.length); > > I've found this to be reliable. FYI Problems with using setObject ()=20= > with blobs is not > specific to Derby.=A0 I've had to use the above with MySQL and Oracle=20= > as well. > > bw > > Suavi Ali Demir wrote: > How about you first serialize your object into a > byte[] and then do a setBytes() ? And then to read it > back you can do getBytes() and then deserialize from > that byte[]. Would that work? > Regards, > Ali > > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > Craig Russell Architect, Sun Java Enterprise System http://java.sun.com/products/jdo 408 276-5638 mailto:Craig.Russell@sun.com P.S. A good JDO? O, Gasp! --Apple-Mail-130--466210126 Content-Transfer-Encoding: quoted-printable Content-Type: text/enriched; charset=ISO-8859-1 Hi Mithun, I think that Barnet was talking about using the PreparedStatement interface and avoiding the Blob interface entirely. That is, PreparedStatement ps =3D conn.PrepareStatement("insert into EMPLOYEE(ID, IMAGE) values(?,?)"); ps.setInt(1, id); byte[] b =3D ... // serialize arbitrary object to byte[] ByteArrayInputStream ins =3D new ByteArrayInputStream(b); ps.setBinaryStream(2, ins, b.length); int result =3D ps.executeUpdate(); You can use a similar technique on input, using the getBinaryStream method of ResultSet. The binary stream methods of PreparedStatement and ResultSet are highly portable across vendors. Craig On Feb 18, 2005, at 9:37 PM, Mithun Ruikar wrote: Hello , =A0 Barnet Wagman replied me , to use setBinaryStream method of Blob interface. But How can I instantiate Blob object , as it is interface and I dont know it's implemetation ? =A0 How I can get blob object to call setBinaryStream. =A0 that is : Courier = Newps.setBinaryStream(psParamIndex, ins, b.length); Courier Newfrom where you got this ps and what is the value of psParamIndex. Courier Newthank = you Courier New -- = mithun Barnet Wagman < wrote: I always serialize the object to a byte[]=A0 and then use setBinaryStream(), e.g. byte[] b =3D ... // serialize arbitrary object to byte[] ByteArrayInputStream ins =3D new ByteArrayInputStream(b); ps.setBinaryStream(psParamIndex, ins, b.length); I've found this to be reliable. FYI Problems with using setObject () with blobs is not specific to Derby.=A0 I've had to use the above with MySQL and Oracle as well. bw Suavi Ali Demir wrote: How about you first serialize your object into a byte[] and then do a setBytes() ? And then to read it back you can do getBytes() and then deserialize from that byte[]. Would that work? Regards, Ali __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around=20 http://mail.yahoo.com Craig Russell Architect, Sun Java Enterprise System http://java.sun.com/products/jdo 408 276-5638 mailto:Craig.Russell@sun.com P.S. A good JDO? O, Gasp! --Apple-Mail-130--466210126-- --Apple-Mail-131--466209605 Content-Transfer-Encoding: base64 Content-Type: application/pkcs7-signature; name=smime.p7s Content-Disposition: attachment; filename=smime.p7s MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIGHjCCAtcw ggJAoAMCAQICAw3FWTANBgkqhkiG9w0BAQQFADBiMQswCQYDVQQGEwJaQTElMCMGA1UEChMcVGhh d3RlIENvbnN1bHRpbmcgKFB0eSkgTHRkLjEsMCoGA1UEAxMjVGhhd3RlIFBlcnNvbmFsIEZyZWVt YWlsIElzc3VpbmcgQ0EwHhcNMDUwMTEwMDA0MTA5WhcNMDYwMTEwMDA0MTA5WjBHMR8wHQYDVQQD ExZUaGF3dGUgRnJlZW1haWwgTWVtYmVyMSQwIgYJKoZIhvcNAQkBFhVDcmFpZy5SdXNzZWxsQFN1 bi5DT00wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDti7ZE4rO6oXKbLM02AG9WY55t udmBVL53fb3V3X5S1kvcJOk1NEMIYT/T7Ww+/hE955zvHT29+mIoNe8AW/yj1WUH8uGG2HxhwCHI UQTHmN/ioVJgjwUaYbtNMKbL/NRpnL0QWewdMJS+6IFzFyX7ADFW5cJ+UWNLvNeWAQtN0mtLildn vdOgh50i8YPvACNkCHoomGjXx0azcXbe1X3c5AgRI6e2CZe5k2lRFQFUMqkjdoMtQPoNqJ1BxH9l i4cnabl8mcTwHHl44hrvb8ThqwRf2pfJh2vVuwmgK6z4IWjOk4RQM+0ODsRdq67mBdimJYmPMK1p RMBHzrUsfKxNAgMBAAGjMjAwMCAGA1UdEQQZMBeBFUNyYWlnLlJ1c3NlbGxAU3VuLkNPTTAMBgNV HRMBAf8EAjAAMA0GC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