I think that this is what you need, then (from the link given above)
"Recipe" is a JPA Entity and the "thumb" and "image" fields are defined as
byte[]. So basically, you'd do the same thing with raw
JDBC except that instead of having the scaled and unscaled images as object properties, you'd just make them local variables. The parameter "bs" is a byte[] that in the webapp came in as part of the upload, but for a Swing app that was selecting a local file, you'd simply construct a byte array by opening the input file as a bytestream and reading it into RAM. Or cut out the middleman and change the "bs" parameter to pass in the "istream" directly.
Since I'm storing both image and thumnail as BLOBs I have a special utility method that I can call to ensure that the stored image isn't too large and scales it down to no more than 512×512, but that's not essential.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.