PreparedStatement insert = null; // private Statement delete = null; //private Statement edit = null; private ResultSet registros = null; private int action; private void primeiroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_primeiroActionPerformed try { registros.first(); exibe(); message(9); habilitar(); } catch (SQLException ex) { message(5); JOptionPane.showMessageDialog(null, ex.getMessage()); } }//GEN-LAST:event_primeiroActionPerformed private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened cancela.setVisible(false); // TODO add your handling code here: // Conecta o banco de dados try { Class.forName("org.gjt.mm.mysql.Driver").newInstance(); con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/teste?autoReconnect=true","root", ""); if(!con.isClosed()) message(6); } catch(Exception e) { message(3); JOptionPane.showMessageDialog(null, e.getMessage()); } // prepara a consulta try { select = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); } catch (SQLException ex) { message(5); JOptionPane.showMessageDialog(null, ex.getMessage()); } try { // executando a consulta registros = select.executeQuery("select * from produtos where ativo = 1"); } catch (SQLException ex) { message(7); JOptionPane.showMessageDialog(null, ex.getMessage()); } try { // carregando registros registros.first(); exibe(); habilitar(); } catch (SQLException ex) { message(2); JOptionPane.showMessageDialog(null, ex.getMessage()); } }//GEN-LAST:event_formWindowOpened private void idActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_idActionPerformed // TODO add your handling code here: }//GEN-LAST:event_idActionPerformed private void ultimoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ultimoActionPerformed try { registros.last(); exibe(); message(9); habilitar(); } catch (SQLException ex) { message(5); JOptionPane.showMessageDialog(null, ex.getMessage()); } }//GEN-LAST:event_ultimoActionPerformed private void anteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_anteriorActionPerformed try { registros.previous(); exibe(); message(9); habilitar(); } catch (SQLException ex) { message(5); JOptionPane.showMessageDialog(null, ex.getMessage()); } }//GEN-LAST:event_anteriorActionPerformed private void proximoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_proximoActionPerformed try { registros.next(); exibe(); message(9); habilitar(); } catch (SQLException ex) { message(5); JOptionPane.showMessageDialog(null, ex.getMessage()); } }//GEN-LAST:event_proximoActionPerformed private void salvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salvarActionPerformed // TODO add your handling code here: if (action == 1){ update(); cancelar(); }else insere(); cancelar(); }//GEN-LAST:event_salvarActionPerformed private void deletarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deletarActionPerformed // TODO add your handling code here: int result = JOptionPane.showConfirmDialog(null,"Deseja Excluir ? ","Excluir",JOptionPane.YES_OPTION); if (result == JOptionPane.YES_OPTION){ delete(); } }//GEN-LAST:event_deletarActionPerformed private void editarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editarActionPerformed action = 1; editar(); // TODO add your handling code here: }//GEN-LAST:event_editarActionPerformed private void cancelaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelaActionPerformed cancelar(); // TODO add your handling code here: }//GEN-LAST:event_cancelaActionPerformed private void maisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_maisActionPerformed novo(); action = 0; // TODO add your handling code here: }//GEN-LAST:event_maisActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Produtos().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton anterior; private javax.swing.JButton cancela; private javax.swing.JButton deletar; private javax.swing.JButton editar; private javax.swing.JTextField id; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JButton mais; private javax.swing.JTextField nome; private javax.swing.JTextField peso; private javax.swing.JTextField preco; private javax.swing.JButton primeiro; private javax.swing.JButton proximo; private javax.swing.JButton salvar; private javax.swing.JLabel status; private javax.swing.JButton ultimo; // End of variables declaration//GEN-END:variablespublic void exibe(){ try { id.setText(registros.getString("id")); nome.setText(registros.getString("nome")); preco.setText(registros.getString("preco")); peso.setText(registros.getString("peso")); } catch (SQLException e){ message(2); JOptionPane.showMessageDialog(null, e.getMessage()); }}public void insere(){ try { insert = (PreparedStatement) con.prepareStatement("insert into produtos (nome, preco, peso, ativo) values ( ?, ?, ?, ?)"); //insert.setString(1, "default"); insert.setString(1, nome.getText()); insert.setFloat(2, Float.parseFloat(preco.getText())); insert.setFloat(3, Float.parseFloat(peso.getText())); insert.setInt(4, 1); insert.execute(); registros = select.executeQuery("select * from produtos where ativo = 1"); exibe(); message(4); } catch (SQLException ex) { message(1); JOptionPane.showMessageDialog(null, ex.getMessage()); }}public void update(){ try { insert = (PreparedStatement) con.prepareStatement("update produtos set nome = ?, preco = ?, peso = ? where id ="+id.getText()); insert.setString(1, nome.getText()); insert.setFloat(2, Float.parseFloat(preco.getText())); insert.setFloat(3, Float.parseFloat(peso.getText())); insert.executeUpdate(); registros = select.executeQuery("select * from produtos where