From: | Xavier Poinsard <xavier(dot)poinsard(at)openpricer(dot)com> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Problem with bytea getBytes and setBytes |
Date: | 2003-10-08 11:36:30 |
Message-ID: | 3F83F6BE.5000509@openpricer.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
I am trying to use a bytea column to store binary data, but the getBytes
and setBytes methods aren't working as expected.
I suspect a strange escaping occuring.
I ran the following code :
// insert test value
PreparedStatement stmtInsert connection.prepareStatement("insert into
test_blob (colblob) values(?)");
byte testBytes[] = new byte[255];
for (int i=0;i<255;i++)
testBytes[i]=(byte)(i-128);
stmtInsert.setBytes(1,testBytes);
int count = stmtInsert.executeUpdate();
stmtInsert.close();
stmtInsert = null;
// read and compare test value
PreparedStatement stmtSelect =connection.prepareStatement("select
colblob from test_blob");
ResultSet rs = stmtSelect.executeQuery();
while (rs.next()){
byte resByte[]=rs.getBytes(1);
for (int i=0;i<255;i++){
if (resByte[i]!=testBytes[i])
System.out.println("Problem with byte "+i + " "+resByte[i]+"
different from original " + testBytes[i] );
}
}
rs.close();
The results (truncated) :
Problem with byte 32 -62 different from original -96
Problem with byte 33 -96 different from original -95
Problem with byte 34 -62 different from original -94
Problem with byte 35 -95 different from original -93
Problem with byte 36 -62 different from original -92
Problem with byte 37 -94 different from original -91
Problem with byte 38 -62 different from original -90
...
--
Xavier Poinsard xavier(dot)poinsard(at)openpricer(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Xavier Poinsard | 2003-10-08 11:53:59 | Problem with bytea getBytes and setBytes |
Previous Message | Dave Cramer | 2003-10-07 15:03:51 | Re: Row Lock |