Firebird + Tratamento de erros

11 respostas
F

Pessoal,

Como faço para tratar os erros(exemplo: usuario já castrato ou chave primaria existente) do FireBird??

11 Respostas

C

coloque um try catch na sua classe de insersão!

F

Já estou usando o try!!
Mas não sei como especificar os erros ou tratar os erros que vem do banco!!

C

quais os erros retornados ?

F

Erro abaixo esta relacionado a uma chave primário existente!!

<blockquote>

org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544665. violation of PRIMARY or UNIQUE KEY constraint PK_TIPOMOEDA on table "TIPOMOEDA"

at org.firebirdsql.jdbc.AbstractStatement.executeUpdate(AbstractStatement.java:250)

at servicos.ServMoeda.Cadastrar(ServMoeda.java:31)

at negocio.Moeda.cadastrar(Moeda.java:17)

at interfaces.GuiMoeda$1.actionPerformed(GuiMoeda.java:125)

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)

at org.firebirdsql.gds.GDSException: violation of PRIMARY or UNIQUE KEY constraint PK_TIPOMOEDA on table "TIPOMOEDA"

at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.readStatusVector(AbstractJavaGDSImpl.java:2104)

at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.receiveResponse(AbstractJavaGDSImpl.java:2054)

at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.iscDsqlExecute2(AbstractJavaGDSImpl.java:1146)

at org.firebirdsql.gds.impl.GDSHelper.executeStatement(GDSHelper.java:222)

at org.firebirdsql.jdbc.AbstractStatement.internalExecute(AbstractStatement.java:1087)

at org.firebirdsql.jdbc.AbstractStatement.executeUpdate(AbstractStatement.java:246)

at servicos.ServMoeda.Cadastrar(ServMoeda.java:31)

at negocio.Moeda.cadastrar(Moeda.java:17)

at interfaces.GuiMoeda$1.actionPerformed(GuiMoeda.java:125)

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

kra… tente executar esse seu sql no IBConsole e tu vai ver q o problema n e o java, e sim a sua query q esta errada!

F

Tava querendo tratar os erros do banco para que quando um usuario digitasse um valor ja existente o programa exibi uma mensagem dizendo que o valor digitada ja existia!!

C

Pelo que entendi… qdo o usuário digitar o código do usuário, entao ele verifica se ja existe ? é isso ?

F

Sim! Não queria fazer isto via progamação!!

C

Tp… entao a cada código que o kra digitar, tp… um codigo de usuário, qdo o foco sair do campo ou sei la qual evento tu ta colocando ai, tu faz um select no BD, ok acha ?

F

Bom!!!

K

Pelo menos quanto ao código, voce pode deixar o SGBD cuidar disso. Voce evita de fazer uma consulta ao banco pra verificar isso. O Interbase/Firebird tem generator.
Nao sei se seu problema já se resolveu, mas ta aí a dica.

Criado 12 de junho de 2006
Ultima resposta 17 de jun. de 2006
Respostas 11
Participantes 3