public static void deleteEditora(String nomeDaEditora) throws SQLException { try { Connection con = Dao.getConnection(); String sql = ("DELETE FROM editora WHERE NOME = '" + nomeDaEditora + "';"); PreparedStatement ps = con.prepareStatement(sql); ps.executeUpdate(); } catch (Exception e) { e.printStackTrace(); } }
public static void updateEditora(String valorAtual, String valorNovo, String atributo) throws SQLException { try { Connection con = Dao.getConnection(); String sql = ("UPDATE editora SET " + atributo + " = '" + valorNovo + "' WHERE " + atributo + " = '" + valorAtual + "';"); PreparedStatement ps = con.prepareStatement(sql); ps.executeUpdate(); } catch (Exception e) { e.printStackTrace(); } }
public static void criarEditora(Editora editora) throws SQLException { try { Connection con = Dao.getConnection(); String sql = ("INSERT INTO editora (id, nome, endereco, telefone) VALUES ('" + editora.getId() + "', '" + editora.getNome() + "', '" + editora.getEndereco() + "', '" + editora.getTelefone() + "');"); PreparedStatement ps = con.prepareStatement(sql); ps.executeUpdate(); } catch (Exception e) { e.printStackTrace(); } System.out.println("Registro Realizado."); }
public static List<Editora> readEditora() throws SQLException { List<Editora> lista = new ArrayList<Editora>(); try { Connection con = Dao.getConnection(); String sql = ("SELECT * FROM editora order by nome"); PreparedStatement ps = con.prepareStatement(sql); ResultSet rs = ps.executeQuery(); Editora editora; while (rs.next()) { editora = new Editora(); editora.setId(rs.getInt("id")); editora.setNome(rs.getString("nome")); editora.setEndereco(rs.getString("endereco")); editora.setTelefone(rs.getString("telefone")); lista.add(editora); } } catch (Exception e) { e.printStackTrace(); } return lista; }