Пример #1
0
  @Override
  public void atualizar(Editora editora) {
    System.out.println(editora.getCnpj());
    Connection conexao = connectionFactory.conectar();
    String sql = "UPDATE tbEditora " + "SET cnpj=?, nome=?, logo=? WHERE cnpj=?";
    PreparedStatement ps = null;
    try {
      ps = conexao.prepareStatement(sql);
      ps.setString(1, editora.getCnpj());
      ps.setString(2, editora.getNome());
      ps.setBlob(3, editora.getLogoBlob());
      ps.setString(4, editora.getCnpj());
      ps.executeUpdate();
      ps.close();
      conexao.close();

    } catch (SQLException e) {
      e.printStackTrace();
      throw new RuntimeException(e.getMessage());
    } finally {
      try {
        ps.close();
        conexao.close();
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
  }
Пример #2
0
 @Override
 public void inserir(Editora editora) {
   Connection conexao = connectionFactory.conectar();
   String sql = "INSERT INTO tbEditora(cnpj, nome, logo) " + "VALUES (?,?,?)";
   PreparedStatement ps = null;
   try {
     ps = conexao.prepareStatement(sql);
     ps.setString(1, editora.getCnpj());
     ps.setString(2, editora.getNome());
     ps.setBlob(3, editora.getLogoBlob());
     ps.executeUpdate();
     ps.close();
     conexao.close();
   } catch (SQLException e) {
     e.printStackTrace();
     throw new RuntimeException(e.getMessage());
   } finally {
     try {
       ps.close();
       conexao.close();
     } catch (SQLException e) {
       e.printStackTrace();
     }
   }
 }