Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W4sfD-0001yC-2W for pgsql-jdbc@arkaria.postgresql.org; Sun, 19 Jan 2014 13:43:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1W4sfC-0007dP-I4 for pgsql-jdbc@arkaria.postgresql.org; Sun, 19 Jan 2014 13:43:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W4sfB-0007dJ-Tv for pgsql-jdbc@postgresql.org; Sun, 19 Jan 2014 13:43:45 +0000 Received: from prod2.officenet.no ([195.159.87.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W4sf8-0005E2-KA for pgsql-jdbc@postgresql.org; Sun, 19 Jan 2014 13:43:45 +0000 Received: from localhost ([127.0.0.1] helo=prod2) by prod2.officenet.no with esmtp (Exim 4.76) (envelope-from ) id 1W4sd6-0003XB-0p for pgsql-jdbc@postgresql.org; Sun, 19 Jan 2014 14:41:36 +0100 Date: Sun, 19 Jan 2014 14:41:35 +0100 (CET) From: Andreas Joseph Krogh To: pgsql-jdbc@postgresql.org Message-ID: In-Reply-To: Subject: Re: Will Connection.createBlob be implemented any time soon? MIME-Version: 1.0 X-Mailer: OfficeNet Mail 1.9.0-SNAPSHOT X-Pg-Spam-Score: -2.4 (--) Content-Type: multipart/alternative; boundary="----=_Part_47_1381929750.1390138895784" List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org ------=_Part_45_394958509.1390138895602 Content-Type: multipart/related; boundary="----=_Part_46_195707886.1390138895602" ------=_Part_46_195707886.1390138895602 Content-Type: multipart/alternative; boundary="----=_Part_47_1381929750.1390138895784" ------=_Part_47_1381929750.1390138895784 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable P=C3=A5 s=C3=B8ndag 19. januar 2014 kl. 14:31:00, skrev Thomas Kellerer < spam_eater@gmx.net >: Andreas Joseph Krogh wrote= on=20 19.01.2014 14:14: > $subject > It'd be nice to be able to do: >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 val b =3D = con.createBlob() >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 val os =3D= b.setBinaryStream(1) >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 IOUtils.co= pyLarge(is, os, new Array[Byte](1024 * 1024)) > Is there a work-around for it? Using PreparedStatement.setBinaryStream() works without problems. You don't even need the intermediate Blob instance: PreparedStatement pstmt =3D con.createStatement("...."); pstmt.setBinaryStream(1, is); =C2=A0 =C2=A0or pstmt.setBinaryStream(1, is, length);=C2=A0 // if the length is known =C2= =A0 I'm using=20 JPA and need to be able to set a (new) Blob as a field, like this: =C2=A0 = =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=20 =C2=A0=C2=A0=C2=A0=C2=A0 val b =3D con.createBlob() =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0val os =3D b.setBinaryStream(1) =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0IOUtils.copyLarge(is, os, new Array[Byte](1024 * 1024)) =C2=A0=C2=A0=20 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 myEntity.set= Data(b) =C2=A0 Where MyEntity has a field "data" which is=20 of type "Blob" =C2=A0 -- Andreas Joseph Krogh =C2=A0 =C2=A0 =C2=A0 mob: +47 9= 09 56 963 Senior Software Developer / CTO - OfficeNet AS - http://www.officenet.no Public key: http://home.officenet.no/~andreak/public_key.asc =C2=A0 ------=_Part_47_1381929750.1390138895784 Content-Type: text/html;charset=UTF-8 Content-Transfer-Encoding: quoted-printable
P=C3=A5 s=C3=B8ndag 19. januar 2014 kl. 14:31:00, skrev Thomas Kellere= r <spam_eater@gm= x.net>:
And= reas Joseph Krogh wrote on 19.01.2014 14:14:
> $subject
> It'd be nice to be able to do:
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 val b = =3D con.createBlob()
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 val os = =3D b.setBinaryStream(1)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 IOUtils.= copyLarge(is, os, new Array[Byte](1024 * 1024))
> Is there a work-around for it?

Using PreparedStatement.setBinaryStream() works without problems.
You don't even need the intermediate Blob instance:

PreparedStatement pstmt =3D con.createStatement("....");

pstmt.setBinaryStream(1, is);
=C2=A0 =C2=A0or
pstmt.setBinaryStream(1, is, length);=C2=A0 // if the length is known
=C2=A0
I'm using JPA and need to be able to set a (new) Blob as a field, like= this:
=C2=A0
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0= =C2=A0 val b =3D con.createBlob()
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0val os =3D b.setBinaryStream(1)
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0IOUtils.copyLarge(is, os, new Array[Byte](1024 * 1024))
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0= myEntity.setData(b)
=C2=A0
Where MyEntity has a field "data" which is of type "Blo= b"
=C2=A0
--
Andreas Joseph Krogh <andreak@officenet.no>=C2=A0 =C2=A0 =C2=A0 mob: = +47 909 56 963
Senior Software Developer / CTO - OfficeNet AS - http://www.officenet.no Public key: http://home.officenet.no/~andreak/public_key.asc
=C2=A0
------=_Part_47_1381929750.1390138895784-- ------=_Part_46_195707886.1390138895602-- ------=_Part_45_394958509.1390138895602--