OLa tudo bem? estou tentando excluir porem esta dando este erro pq?
codigo
package br.com.drogaria.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import br.com.drogaria.factory.ConexaoFactory;
import br.com.drogaria.domain.Fabricante;
public class FabricanteDAO{
public void salvar(Fabricante f) throws SQLException{
StringBuilder sql = new StringBuilder();
sql.append("INSERT INTO Fabricante “);
sql.append(”(descricao) ");
sql.append(“VALUES (?)”);
Connection conexao = ConexaoFactory.conectar();
PreparedStatement comando = conexao.prepareStatement(sql.toString());
comando.setString(1, f.getDescricao());
comando.executeUpdate();
}
public void excluir(Fabricante f)throws SQLException{
StringBuilder sql = new StringBuilder();
sql.append("DELETE FROM fabricante");
sql.append("WHERE codigo = '?' ");
Connection conexao = ConexaoFactory.conectar();
PreparedStatement comando = conexao.prepareStatement(sql.toString());
comando.setLong(1, f.getCodigo());
comando.executeUpdate();
}
public static void main(String[] args) {
/*Fabricante f1 = new Fabricante();
f1.setDescricao("Descricao 1");
Fabricante f2 = new Fabricante();
f2.setDescricao("descricao 2");
FabricanteDAO fdao = new FabricanteDAO();
try {
fdao.salvar(f1);
fdao.salvar(f2);
System.out.println("Salvo com Sucesso");
} catch (SQLException e) {
System.out.println("Ocorreu erro");
e.printStackTrace();
}*/
Fabricante f1 = new Fabricante();
f1.setCodigo(2L);
FabricanteDAO fdao = new FabricanteDAO();
try {
fdao.excluir(f1);
System.out.println("removido");
} catch (SQLException e) {
System.out.println("Sem sucesso");
e.printStackTrace();
}
}
}
erro
org.postgresql.util.PSQLException: O índice da coluna está fora do intervalo: 1, número de colunas: 0.
at org.postgresql.core.v3.SimpleParameterList.bind(SimpleParameterList.java:68)
at org.postgresql.core.v3.SimpleParameterList.setBinaryParameter(SimpleParameterList.java:135)
at org.postgresql.jdbc.PgPreparedStatement.bindBytes(PgPreparedStatement.java:1095)
at org.postgresql.jdbc.PgPreparedStatement.setLong(PgPreparedStatement.java:326)
at br.com.drogaria.dao.FabricanteDAO.excluir(FabricanteDAO.java:34)
at br.com.drogaria.dao.FabricanteDAO.main(FabricanteDAO.java:61)