Re: import_bytea function

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: import_bytea function
Date: 2016-10-08 15:13:12
Message-ID: ntb2e5$loa$2@blaine.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Stephen Davies schrieb am 08.10.2016 um 02:57:
> I will have to regenerate that code to get the exact error message text but it basically said that the parameter substitution was invalid.
>
> A follow-up question.
> Once the bytea column is populated, how best to display the content in a web page?
>
> I have :
>
> byte [] imgB;
> ResultSet rs = st1.executeQuery("select pic from part where pno='" + p + "'");
> if(rs.next()){
> imgB = rs.getBytes(1);
> if (imgB != null){
> out.write("Content-type: image/jpeg");
> out.write("Content-length: " + (int)imgB.length);
> out.write(imgB.toString());
> }
> }
>
> but this does not work.
> The toString() looks wrong but removing it makes the write fail.

Assuming you are doing this in a Servlet, you should be writing the binary data to the HttpServletResponse

Something like:

ResultSet rs = st1.executeQuery("select pic from part where pno='" + p + "'");
if (rs.next())
{
byte[] image = rs.getBytes(1);
response.setContentType("image/jpeg");
response.setIntHeader("Content-length", (int)image.length);
response.getOutputStream().write(image);
}

But this is getting quite off-topic now.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andres Freund 2016-10-08 22:45:32 Re: Lock contention in TransactionIdIsInProgress()
Previous Message Thomas Kellerer 2016-10-08 15:10:31 Re: import_bytea function