BUG #1594: ResultSet.getBytes() vs db encoding latin1

From: "Pascal Lambert" <pascall(at)caddy(dot)ca>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #1594: ResultSet.getBytes() vs db encoding latin1
Date: 2005-04-12 20:31:05
Message-ID: 20050412203105.BE8EDF1150@svr2.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 1594
Logged by: Pascal Lambert
Email address: pascall(at)caddy(dot)ca
PostgreSQL version: 7.3.9
Operating system: linux
Description: ResultSet.getBytes() vs db encoding latin1
Details:

The bug is related with the jdbc driver.

The getBytes() method of the ResultSet didn't return the correct bytes. It
can be reprodure easly with the following with a database using encoding
LATIN1. But it work fine when using UNICODE encoding.

_________________________________________________________
/**
* CREATE DATABASE BUGBYTEA WITH ENCODING='LATIN1';
* CREATE TABLE IMAGES ( IMAGE BYTEA );
*/
public class BugBytea
{
public static void main(String[] args)
{
try {
BugBytea o = new BugBytea();
o.run();
} catch (Exception e) {
e.printStackTrace();
}
}

private void run() throws Exception
{
Class.forName("org.postgresql.Driver");
Connection con =
DriverManager.getConnection("jdbc:postgresql://caddy_java/bugbytea",
"postgres", "");

Statement stmt = con.createStatement();
stmt.executeUpdate("truncate table images");
PreparedStatement pstmt = con.prepareStatement("insert into images
values (?)");

byte[] bytes = {-84, -19, 0, 5};
pstmt.setBytes(1, bytes);
pstmt.execute();

ResultSet rs = stmt.executeQuery("select image from images");
rs.next();
byte[] result = rs.getBytes(1);

System.out.println("bytes=");
this.printByte(bytes);
System.out.println("result=");
this.printByte(result);
}

private void printByte(byte[] bytes)
{
for (int i=0; i<bytes.length; i++)
{
if (i>0) System.out.print(", ");
System.out.print(bytes[i]);
}
System.out.println("");
}
}

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Kris Jurka 2005-04-13 08:18:50 Re: BUG #1594: ResultSet.getBytes() vs db encoding latin1
Previous Message Tom Lane 2005-04-12 18:55:56 Re: BUG #1593: Problem with installation