java.sql.SQLException: Before start of result set [duplicate]

You must call rs.next() (and check that it returns true) to access the first row of the result set:

if (rs.next() {
    InputStream stream = rs.getBinaryStream(1);
    ...

Also not that the index should be 1, since your query only selects one column.

I also don’t understand the point in casting the int to a char. The method takes an int as argument. A cast to byte would at least be logical, but bytes and char are not the same thing in Java.

Leave a Comment