Mathieu Turcotte
Mathieu Turcotte

Reputation: 354

Trouble reading a bytea (blob...) from database in java (1.5)

First off, I should mention I'm an absolute beginner in Java. I touched it a tiny little bit in school, 12 years ago. Haven't touched it since. Sorry if the question might sound a little bit basic.

We need to modify our client's web service which runs on Java 1.5. Yes, this is a very old version of java, and yes, until further notice, we are stuck with it. It's not our decision...

I need to read data from a Postgre table. The table has an auto increment ID, a vehicule ID, a data type ID, a timestamp and a data_value field containing a bytea, which represents the value. Each data type has a different data structure.

For example, data type 1 would be the oil temperature, and have only one value: the temperature. The data is represented on 2 bytes, and it is the temperature*10 in fahrenheit.

Data type 2 could be the GPS coordinates, and would be represented on 20 bytes. It has multiple values, where bytes 1-4 would represent the latitude, bytes 5-8 would be the longitude, 9-10 the altitude, 11 would be the number of satellites etc.

The web service uses a org.springframework.jdbc.support.rowset.SqlRowSet to read the data from the other tables. The problem is that, in 1.5 at least, the SqlRowSet class has no way of reading a byte array/blob. I can read ints, doubles, strings, booleans, objects, and even bytes, but no byte array.

is there a way to convert the SqlRowSet into another type of recordset/rowset that would let me read byte arrays? Or is there another method of doing this that I'm not aware of?

I could try showing some of the code we have, but I don'T know what you guys would need to see, let me know if you need further info!

Thank you,

Upvotes: 0

Views: 695

Answers (1)

Basu
Basu

Reputation: 131

Can you not use something like below?

Blob obj = (Blob) rowSet.getObject("columnLabel");

Upvotes: 1

Related Questions