run:
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'vagner' in 'field list'
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1604)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1519)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1504)
at controlbus.BD.InserirUsuario.CadastrarUsuario(InserirUsuario.java:34)
at controlbus.Funcoes.Usuario.PegarDadosUsuario(Usuario.java:266)
at controlbus.Funcoes.Usuario.bt_gravarActionPerformed(Usuario.java:235)
at controlbus.Funcoes.Usuario.access$200(Usuario.java:22)
at controlbus.Funcoes.Usuario$3.actionPerformed(Usuario.java:107)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6216)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5981)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4583)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
CONSTRUÍDO COM SUCESSO (tempo total: 9 segundos)
seria interessante voce observar a estrutura do banco, e postar aqui.
nesse erro aqui at controlbus.BD.InserirUsuario.CadastrarUsuario(InserirUsuario.java:34)
ta informando que: [quote]Unknown column ‘vagner’ in ‘field list’ [/quote]
ou seja, não existe a coluna ‘vagner’ na sua tabela quando PARECE que você está tentando cadastrar um novo usuário na coluna ‘vagner’
Está ocorrendo algum erro de sintaxe no seu código, que é oque está sendo falado por essa parte da Exception: MySQLSyntaxErrorException
Se puder, poste o código da rotina que você está escrevendo pra se cadastrar um novo usuário
a.moraissoares ai encima ta o codigo, eu não estou tentando gravar na coluna vagner, as colunas que eu estou gravando são (login, senha, nivel_acesso) e essas colunas ai tem no banco de dados.
talvez não seja na hora de inserir, mas na hora de recuperar o campo, precisa ver a ordem da chamada dos métodos… veja a stack trace e vá colocando break-points nas linhas que dá erro, vai te ajudar a descobrir o problema
run:
java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.Statement.checkForDml(Statement.java:417)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1383)
at controlbus.BD.InserirUsuario.CadastrarUsuario(InserirUsuario.java:34)
at controlbus.Funcoes.Usuario.PegarDadosUsuario(Usuario.java:266)
at controlbus.Funcoes.Usuario.bt_gravarActionPerformed(Usuario.java:235)
at controlbus.Funcoes.Usuario.access$200(Usuario.java:22)
at controlbus.Funcoes.Usuario$3.actionPerformed(Usuario.java:107)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6216)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5981)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4583)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
CONSTRUÍDO COM SUCESSO (tempo total: 10 segundos)
cara veja o novo erro que deu com o pstm.ExecuteQuerey();
É importante você tentar entender o que o stackTrace está querendo te dizer.
se ele não funcionou com executeQuery()
tenta assim: execute();
Vou tentar resumir aqui.
Se vc usa o Statement simples, você tem os métodos
executeQuery(query), e executeUpdate(query)
Se vc usa o PreparedStatement, é indutivo que vc vai prepara sua query, ou seja, usar aquelas interrogações que vc questionou em outro tópico.
logo, se vc usa o preparedStatement, é interessante que vc o use da forma correta.
Para o preparedStatement, temos os métodos
execute(); // que retorna um boolean
executeQuery()// que retorna um resultSet
executeUpdate // que retorna um int
então, vc deve montar corretamente sua query, e optar por uma dessas opções que eu irformei.
Sugerindo ainda que se faça os imports corretos
import java.sql.PreparedStatement; // para o PreparedStatement
import java.sql.Statement; // para o Statement
vamos lá, tente denovo e poste aqui se resolveu o problema.
ok, deixei o codigo do jeito que vc mostrou veja o novo erro:
run:
java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.Statement.checkForDml(Statement.java:417)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1383)
at controlbus.BD.InserirUsuario.CadastrarUsuario(InserirUsuario.java:34)
at controlbus.Funcoes.Usuario.PegarDadosUsuario(Usuario.java:266)
at controlbus.Funcoes.Usuario.bt_gravarActionPerformed(Usuario.java:235)
at controlbus.Funcoes.Usuario.access$200(Usuario.java:22)
at controlbus.Funcoes.Usuario$3.actionPerformed(Usuario.java:107)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6216)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5981)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4583)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
CONSTRUÍDO COM SUCESSO (tempo total: 10 segundos)
neste erro postado anteriro foi usad o ExecuteQuery();
agora usando o Execute veja o erro:
run:
java.sql.SQLException: Field 'tb_funcionario_tb_endereço_id_endereco' doesn't have a default value
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:882)
at controlbus.BD.InserirUsuario.CadastrarUsuario(InserirUsuario.java:34)
at controlbus.Funcoes.Usuario.PegarDadosUsuario(Usuario.java:266)
at controlbus.Funcoes.Usuario.bt_gravarActionPerformed(Usuario.java:235)
at controlbus.Funcoes.Usuario.access$200(Usuario.java:22)
at controlbus.Funcoes.Usuario$3.actionPerformed(Usuario.java:107)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6216)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5981)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4583)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
CONSTRUÍDO COM SUCESSO (tempo total: 8 segundos)
Bom, vemos então que o erro anterior foi solucionado.
De que se trata esses valores q o stackTrace ta mostrando:
‘tb_funcionario_tb_endereço_id_endereco’
me parece q vc não está inserindo nessas colunas, e como vc não configurou o banco pra entrar NULL quando não inserir nada no campo, ele ta dando esse erro. Outra opção, caso não não configure pra setar NULL, vc deve falar quais os valores DEFAULT que vão entrar, quando vc inserir um registro no banco, sem falar todos valores.
agora to indo dormir, caso não resolva o problema, amanha qndo entrar vejo onde está seu problema.
qqer coisa, me manda seu msn por MP, que agente conversa amanha