[RESOLVIDO]
Estou com o seguinte erro ao executar, para fazer inserção em 2 tabelas, recuperando o id da primeira erro: org.postgresql.util.PSQLException: ERROR: invalid input syntax for integer: “id”
Podem me ajudar?
public class PessoasDaoBd implements PessoaDao{
private int id;
@Override
public int insert(Pessoas pessoas) {
try {
Connection connection = FabricaConexoes.getConexao();
Statement statement = connection.createStatement();
statement.executeUpdate(
String.format(
"INSERT INTO pessoas (nome)"
+ "VALUES ('%s')",
pessoas.getNome()));
ResultSet rs;
rs = statement.executeQuery(String.format("SELECT nextval('pessoas_id_pessoa_seq'::regclass) as id;"));
while(rs.next()){
id = rs.getInt("id");
}
statement.executeUpdate(
String.format(
"INSERT INTO enderecos (id_pessoa, endereco)"
+ "VALUES ('id', '%s')",
pessoas.getEndereco()));
return 0;
} catch (SQLException ex) {
System.err.println("Erro");
ex.printStackTrace();
}
return -1;
}
}