PostGreSql e Java

7 respostas
M

Pessoal!!

estou desenvolvendo um sistema desktop com postgre e java. É o seguinte. Tenho um campo que é do tipo float no banco, mas por motivo de validação do campo (tirar virgulas e pontos de lugares errados) defini este campo no java como string. Quando tento inserir um elemento dá o seguinte erro:

<blockquote>java.sql.SQLException: ERROR: column valor_maior_compra is of type numeric but expression is of type character varying

at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1365)

at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1160)

at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:172)

at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:387)

at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:328)

at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:280)

at br.com.sstintas.modelo.bd.GerenciadorBDReferenciaJuridico.inserir(GerenciadorBDReferenciaJuridico.java:32)

at br.com.sstintas.view.ClienteJuridicoView$1.actionPerformed(ClienteJuridicoView.java:1251)

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.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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)</blockquote>

Alguma sugestão de como resolver?!?

7 Respostas

BrunoBastosPJ

na tua query você botou o valor_maior_compra entre ’ '?

M

Não coloquei não. Mas para testar coloquei e deu o seguinte erro:

<blockquote>java.sql.SQLException: ERROR: syntax error at or near “‘valor_maior_compra’”

at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1365)

at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1160)

at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:172)

at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:387)

at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:328)

at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:280)

at br.com.sstintas.modelo.bd.GerenciadorBDReferenciaJuridico.inserir(GerenciadorBDReferenciaJuridico.java:32)

at br.com.sstintas.view.ClienteJuridicoView$1.actionPerformed(ClienteJuridicoView.java:1251)

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.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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)</blockquote>
C

Posta o código!

M

Esse é o trecho do código onde eu pego o valor do campo. Primeiro verifico se existem pontos e vírgulas, daí adiciono.

str = tfValorUltimaCompra.getText(); if (str.length() > 0){ str = str.replaceAll("\.", ","); str = str.substring(0, str.lastIndexOf(",")) + "." + str.substring(str.lastIndexOf(",")+1, str.length()); refjur.setValorUltimaCompra(str); }

C

Ja testou c esse valor esta do jeito que tu quer quando vai enviar pra o BD ?

M

Como seria esse teste??? :oops:

BrunoBastosPJ

str = tfValorUltimaCompra.getText(); if (str.length() > 0){ str = str.replaceAll("\.", ","); str = str.substring(0, str.lastIndexOf(",")) + "." + str.substring(str.lastIndexOf(",")+1, str.length()); System.out.println("O valor é = "+str); refjur.setValorUltimaCompra(str); }

Criado 12 de julho de 2006
Ultima resposta 13 de jul. de 2006
Respostas 7
Participantes 3