I am trying to store a zipped string into a CLOB column, just like this

String compressedMatrix = ZipUtils.compress(matrix.getBuffer().toString());
pstmt.setString(2,compressedMatrix);

where ZipUtils is

        public static String compress(String is) throws Exception{
                 ByteArrayInputStream bais = new 
ByteArrayInputStream(is.getBytes());
                 ByteArrayOutputStream baos = new ByteArrayOutputStream();
                 compress(baos,bais);
                 byte[] xx = baos.toByteArray();
                 return new String(xx);
        }
        public static void compress(OutputStream os, InputStream is) throws 
Exception{
                byte[] buf = new byte[1024];
       ZipOutputStream out = new ZipOutputStream(os);
       out.putNextEntry(new ZipEntry("compressed"));
       int len;
       while ((len = is.read(buf)) > 0) {
           out.write(buf, 0, len);
       }
       out.close();
       is.close();
       out.close();
        }

but I am getting this exception

Exception in thread "main" org.apache.derby.client.am.SqlException: A
truncation error was encountered trying to shrink CLOB 'PK' to
length

        at org.apache.derby.client.am.Statement.completeExecute(Unknown Source)
        at 
org.apache.derby.client.net.NetStatementReply.parseEXCSQLSTTreply(Unknown
Source)
        at org.apache.derby.client.net.NetStatementReply.readExecute(Unknown 
Source)
        at org.apache.derby.client.net.StatementReply.readExecute(Unknown 
Source)
        at org.apache.derby.client.net.NetPreparedStatement.readExecute_(Unknown
Source)
        at org.apache.derby.client.am.PreparedStatement.readExecute(Unknown 
Source)
        at org.apache.derby.client.am.PreparedStatement.flowExecute(Unknown 
Source)
        at org.apache.derby.client.am.PreparedStatement.executeX(Unknown Source)
        at org.apache.derby.client.am.PreparedStatement.execute(Unknown Source)

I suppose that I don't have to specify charsets because it's assuming
it's the default one (UTF-8)

Any ideas? Invalid chars? In a CLOB column?

[]

Kenji
_______________________
http://kenjiria.blogspot.com
http://gaitabh.blogspot.com

Reply via email to