@Override public List<barang> sortBarangbyMerek() throws BarangException { List<barang> list = new ArrayList<barang>(); Statement statement = null; barang barang = null; try { connection.setAutoCommit(false); statement = connection.createStatement(); ResultSet rs = statement.executeQuery(sortBymerek); while (rs.next()) { barang = new barang(); barang.setIdBarang(rs.getString("idbarang")); barang.setIdBarcode(rs.getString("idbarcode")); barang.setNamaBarang(rs.getString("namabarang")); barang.setTipe(rs.getString("tipe")); barang.setMerek(rs.getString("merek")); barang.setHargamodal(rs.getInt("hargamodal")); barang.setEceran(rs.getInt("eceran")); barang.setGrosir(rs.getInt("grosir")); barang.setSatuan(rs.getString("satuan")); barang.setStok(rs.getInt("stok")); barang.setStokMinimum(rs.getInt("stok_minimum")); barang.setSupplier(rs.getString("supplier")); barang.setKeterangan(rs.getString("keterangan")); barang.setGambarHasil(rs.getBlob("gambar")); barang.setKategori(rs.getString("kategori")); list.add(barang); } connection.commit(); return list; } catch (SQLException exception) { try { connection.rollback(); } catch (SQLException ex) { } throw new BarangException(exception.getMessage()); } finally { try { connection.setAutoCommit(true); } catch (SQLException ex) { } if (statement != null) { try { statement.close(); } catch (SQLException exception) { } } } }
@Override public void updateBarang(barang barang) throws BarangException { PreparedStatement statement = null; try { connection.setAutoCommit(false); statement = connection.prepareStatement(updateBarang); statement.setString(1, barang.getIdBarang()); statement.setString(2, barang.getIdBarcode()); statement.setString(3, barang.getNamaBarang()); statement.setString(4, barang.getTipe()); statement.setString(5, barang.getMerek()); statement.setInt(6, barang.getHargamodal()); statement.setInt(7, barang.getEceran()); statement.setInt(8, barang.getGrosir()); statement.setString(9, barang.getSatuan()); statement.setInt(10, barang.getStok()); statement.setInt(11, barang.getStokMinimum()); statement.setString(12, barang.getSupplier()); statement.setString(13, barang.getKeterangan()); try { statement.setBlob(14, new FileInputStream(barang.getGambar())); } catch (FileNotFoundException ex) { Logger.getLogger(ReminderDaoImpl.class.getName()).log(Level.SEVERE, null, ex); } statement.setString(14, barang.getKategori()); statement.executeUpdate(); connection.commit(); } catch (SQLException exception) { try { connection.rollback(); } catch (SQLException ex) { } JOptionPane.showMessageDialog(null, "Insert barang gagal karena " + exception); } finally { try { connection.setAutoCommit(true); } catch (SQLException ex) { } if (statement != null) { try { statement.close(); } catch (SQLException exception) { } } } }