Olá, pessoal!
Primeira vez que uso PL no Postgresql. tentei várias vezes e não consegui funcionar. veja mensagem de erro.
[quote]
org.postgresql.util.PSQLException: ERRO: função inserir_lote(bigint, character varying, character varying, character varying, double precision, integer) não existe
Dica: Nenhuma função corresponde com o nome e os tipos de argumentos informados. Você precisa adicionar conversões de tipo explícitas.
Posição: 8
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
at bd.conexao.conexaoBD.inserirQuery(conexaoBD.java:67)
at bd.lote.Lote.inserirLoteInformate(Lote.java:22)
at bd.arquivo.Arquivos.carregarArquivo(Arquivos.java:73)
at bd.arquivo.Arquivos.procuraArquivo(Arquivos.java:29)
at bd.graficos.TelaLote.actionPerformed(TelaLote.java:63)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)[/quote]
Segue o código que estou utilizando
public ResultSet inserirQuery(Connection conn, Informate i ) throws SQLException{
String sql = "select inserir_lote(?,?,?,?,?,?)";
PreparedStatement st = conn.prepareStatement(sql);
st.setLong(1, i.getCpf());
st.setString(2,i.getNome());
st.setString(3,i.getDtInicio());
st.setString(4, i.getDtFinal());
st.setDouble(5,i.getValorTotal());
st.setInt(6, i.getFinalidade());
System.out.println("Gerando procedimento");
return st.executeQuery();
}
No PostgreSql
CREATE OR REPLACE FUNCTION inserir_lote(cpf bigint, nome_info character varying, data_inicio varchar(8), data_final varchar(8), valor numeric, finalidade integer)
RETURNS character varying AS
$$
declare
cod_info int;
cod_lt int;
begin
insert into sgl_informate (cod_cpf,nome) values(cpf, nome_info);
select max(cod_informate) into cod_info from sgl_informate;
--to_date('05 Dec 2000', 'DD Mon YYYY')
insert into sgl_lote(cod_informate,dt_inicio,dt_final,valor_total, cod_finalidade) values (cod_info, to_date(data_inicio,'YYYYMMDD'), to_date(data_final,'YYYYMMDD'),valor,finalidade);
select max(cod_lote) into cod_lt from sgl_lote;
return 'OK - '||cod_lt;
end;
$$
LANGUAGE plpgsql;
Aguardo pelo ajuda para resolver esse problemas. Obrigado!!