Code example for ResultSet

Methods: getBlob, getInt, getString, next

0
            image = new ImageDTO();
            PreparedStatement ps = con.prepareStatement("select * from " + tableName + "\n" +
                    "where did=?"); 
            ps.setInt(1, id);
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                image.setId(rs.getInt("did"));
                image.setContentType(rs.getString("phototype"));
                Blob blob = rs.getBlob("photodata");
                if (blob!=null) {
                    int blobSize = (int)blob.length();
                    byte[] outData = new byte[blobSize];
                    System.arraycopy(blob.getBytes(1, blobSize), 0, outData, 0, blobSize);
                    image.setImgData(outData);
                } 
            } 
        } catch (Exception e) {
            e.printStackTrace();
        } finally { 
            closeConnection(); 
            return image;