@Override public void addImage(ImagesPage img) { String sql = "INSERT INTO imagespages VALUES (null,?,?,?,?)"; PreparedStatement pstat = null; try { conn = myDataSource.getConnection(); pstat = conn.prepareStatement(sql); pstat.setBytes(1, img.getImageData()); pstat.setInt(2, img.getIdPageText()); pstat.setString(3, img.getFilename()); pstat.setString(4, img.getDirectory()); pstat.executeUpdate(); } catch (SQLException ex) { LOG.log(Level.SEVERE, null, ex); } finally { try { if (pstat != null) { pstat.close(); } myDataSource.closeConnection(); } catch (SQLException ex) { LOG.log(Level.SEVERE, null, ex); } } }