[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mysql-java
Subject:    Re: compress/uncompress using java prepared statements
From:       "Ramesh V" <ramesh.mysql () gmail ! com>
Date:       2006-04-21 4:57:17
Message-ID: 249c26c10604202157o7afeca57scd33cc7995c1a58b () mail ! gmail ! com
[Download RAW message or body]


Hi,

I am a bit confused by the below, hope I can get some clarification.

In the database (mysql), I have image data stored in a blob. I can perform
operations like: COMPRESS and UNCOMPRESS on it and the data is fine.

Let's say I COMPRESS (ed) the data and then retrieve it use a SELECT
UNCOMPRESS(IMAGE_DATA) FROM <table>, when I get this using jdbc

ResultSetMetaData rsmd = rs.getMetaData();
System.out.println("SHOW THE COLUMN TYPE: " + rsmd.getColumnType(1));

I am getting the Column type as
"VARCHAR<http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Types.html#VARCHAR>",
whereas if I don't compress the data and do a straight SELECT IMAGE_DATA
..., the resulting
Column Type is a
"LONGVARBINARY<http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Types.html#LONGVARBINARY>
".

Can somebody explain the above? Why does this work fine in the database but
I am not able to select the data into java properly?

How could I conver it into a proper format?

thanks,
Ramesh


On 4/19/06, Ramesh V <ramesh.mysql@gmail.com> wrote:
>
> Hello,
>
> My configuration;
> mysql-connector-java-3.1.12-bin.jar
> mysql5018
>
>
> I am trying to get uncompressed data from mysql using:
> SELECT UNCOMPRESS(FILE_DATA) FROM <table> WHERE <id=11>;
>
> I am using PreparedStatement, I get the result set and do: rs.getBytes(1);
>
> For some reason, the UNCOMPRESS doesn't seem to be working.
>
> I also tried: SELECT UNCOMPRESS(COMPRESS(FILE_DATA)) FROM <table> WHERE
> <id=11>;
>
> The resulting byte[] array seems to be corrupt for some reason.
>
> When I manually UNCOMPRESS the data using the UPDATE stmt in the database
> and then do: SELECT FILE_DATA FROM <table>.....via java, it works fine.
> (Please note: data is not corrupt as I can uncompress it in the db and
> retrieve it)
>
> Does it have to be done differently? Appreciate any suggestions.
>
> thanks,
> Ramesh
>
>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic