ACESSANDO BANCO DE DADOS COM JAVA
Autor: Marco Aurelio | Publicado: 2012-11-10T03:54:00-08:00



/*
&nbsp;* To change this template, choose Tools | Templates
&nbsp;* and open the template in the editor.
&nbsp;*/

/*
&nbsp;* Produtos.java
&nbsp;*
&nbsp;* Created on 10/09/2012, 19:17:24
&nbsp;*/
package gertabela;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import java.awt.Color;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import javax.swing.JOptionPane;

/**
&nbsp;*
&nbsp;* @author mapsilva
&nbsp;*/
public class Produtos extends javax.swing.JFrame {

&nbsp; &nbsp; /** Creates new form Produtos */
&nbsp; &nbsp; public Produtos() {
&nbsp; &nbsp; &nbsp; &nbsp; initComponents();
&nbsp; &nbsp; }

&nbsp; &nbsp; /** This method is called from within the constructor to
&nbsp; &nbsp; &nbsp;* initialize the form.
&nbsp; &nbsp; &nbsp;* WARNING: Do NOT modify this code. The content of this method is
&nbsp; &nbsp; &nbsp;* always regenerated by the Form Editor.
&nbsp; &nbsp; &nbsp;*/
&nbsp; &nbsp; @SuppressWarnings("unchecked")
&nbsp; &nbsp; // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt;//GEN-BEGIN:initComponents
&nbsp; &nbsp; private void initComponents() {

&nbsp; &nbsp; &nbsp; &nbsp; id = new javax.swing.JTextField();
&nbsp; &nbsp; &nbsp; &nbsp; nome = new javax.swing.JTextField();
&nbsp; &nbsp; &nbsp; &nbsp; preco = new javax.swing.JTextField();
&nbsp; &nbsp; &nbsp; &nbsp; peso = new javax.swing.JTextField();
&nbsp; &nbsp; &nbsp; &nbsp; jLabel1 = new javax.swing.JLabel();
&nbsp; &nbsp; &nbsp; &nbsp; jLabel2 = new javax.swing.JLabel();
&nbsp; &nbsp; &nbsp; &nbsp; jLabel3 = new javax.swing.JLabel();
&nbsp; &nbsp; &nbsp; &nbsp; jLabel4 = new javax.swing.JLabel();
&nbsp; &nbsp; &nbsp; &nbsp; primeiro = new javax.swing.JButton();
&nbsp; &nbsp; &nbsp; &nbsp; anterior = new javax.swing.JButton();
&nbsp; &nbsp; &nbsp; &nbsp; proximo = new javax.swing.JButton();
&nbsp; &nbsp; &nbsp; &nbsp; ultimo = new javax.swing.JButton();
&nbsp; &nbsp; &nbsp; &nbsp; mais = new javax.swing.JButton();
&nbsp; &nbsp; &nbsp; &nbsp; editar = new javax.swing.JButton();
&nbsp; &nbsp; &nbsp; &nbsp; salvar = new javax.swing.JButton();
&nbsp; &nbsp; &nbsp; &nbsp; status = new javax.swing.JLabel();
&nbsp; &nbsp; &nbsp; &nbsp; deletar = new javax.swing.JButton();
&nbsp; &nbsp; &nbsp; &nbsp; cancela = new javax.swing.JButton();

&nbsp; &nbsp; &nbsp; &nbsp; setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
&nbsp; &nbsp; &nbsp; &nbsp; addWindowListener(new java.awt.event.WindowAdapter() {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void windowOpened(java.awt.event.WindowEvent evt) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; formWindowOpened(evt);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; });

&nbsp; &nbsp; &nbsp; &nbsp; id.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
&nbsp; &nbsp; &nbsp; &nbsp; id.addActionListener(new java.awt.event.ActionListener() {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void actionPerformed(java.awt.event.ActionEvent evt) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; idActionPerformed(evt);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; });

&nbsp; &nbsp; &nbsp; &nbsp; nome.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N

&nbsp; &nbsp; &nbsp; &nbsp; preco.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N

&nbsp; &nbsp; &nbsp; &nbsp; peso.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N

&nbsp; &nbsp; &nbsp; &nbsp; jLabel1.setText("ID");

&nbsp; &nbsp; &nbsp; &nbsp; jLabel2.setText("NOME");

&nbsp; &nbsp; &nbsp; &nbsp; jLabel3.setText("PREÇO");

&nbsp; &nbsp; &nbsp; &nbsp; jLabel4.setText("PESO");

&nbsp; &nbsp; &nbsp; &nbsp; primeiro.setText("|&lt;&lt;");
&nbsp; &nbsp; &nbsp; &nbsp; primeiro.setToolTipText("Primeiro");
&nbsp; &nbsp; &nbsp; &nbsp; primeiro.addActionListener(new java.awt.event.ActionListener() {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void actionPerformed(java.awt.event.ActionEvent evt) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; primeiroActionPerformed(evt);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; });

&nbsp; &nbsp; &nbsp; &nbsp; anterior.setText("&lt;&lt;");
&nbsp; &nbsp; &nbsp; &nbsp; anterior.setToolTipText("Anterior");
&nbsp; &nbsp; &nbsp; &nbsp; anterior.addActionListener(new java.awt.event.ActionListener() {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void actionPerformed(java.awt.event.ActionEvent evt) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; anteriorActionPerformed(evt);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; });

&nbsp; &nbsp; &nbsp; &nbsp; proximo.setText("&gt;&gt;");
&nbsp; &nbsp; &nbsp; &nbsp; proximo.setToolTipText("Proximo");
&nbsp; &nbsp; &nbsp; &nbsp; proximo.addActionListener(new java.awt.event.ActionListener() {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void actionPerformed(java.awt.event.ActionEvent evt) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proximoActionPerformed(evt);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; });

&nbsp; &nbsp; &nbsp; &nbsp; ultimo.setText("&gt;&gt;|");
&nbsp; &nbsp; &nbsp; &nbsp; ultimo.setToolTipText("Ultimo");
&nbsp; &nbsp; &nbsp; &nbsp; ultimo.addActionListener(new java.awt.event.ActionListener() {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void actionPerformed(java.awt.event.ActionEvent evt) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ultimoActionPerformed(evt);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; });

&nbsp; &nbsp; &nbsp; &nbsp; mais.setText("+");
&nbsp; &nbsp; &nbsp; &nbsp; mais.addActionListener(new java.awt.event.ActionListener() {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void actionPerformed(java.awt.event.ActionEvent evt) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; maisActionPerformed(evt);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; });

&nbsp; &nbsp; &nbsp; &nbsp; editar.setText("editar");
&nbsp; &nbsp; &nbsp; &nbsp; editar.addActionListener(new java.awt.event.ActionListener() {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void actionPerformed(java.awt.event.ActionEvent evt) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; editarActionPerformed(evt);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; });

&nbsp; &nbsp; &nbsp; &nbsp; salvar.setText("salvar");
&nbsp; &nbsp; &nbsp; &nbsp; salvar.setEnabled(false);
&nbsp; &nbsp; &nbsp; &nbsp; salvar.addActionListener(new java.awt.event.ActionListener() {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void actionPerformed(java.awt.event.ActionEvent evt) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; salvarActionPerformed(evt);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; });

&nbsp; &nbsp; &nbsp; &nbsp; deletar.setText("apagar");
&nbsp; &nbsp; &nbsp; &nbsp; deletar.addActionListener(new java.awt.event.ActionListener() {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void actionPerformed(java.awt.event.ActionEvent evt) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; deletarActionPerformed(evt);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; });

&nbsp; &nbsp; &nbsp; &nbsp; cancela.setText("cancela");
&nbsp; &nbsp; &nbsp; &nbsp; cancela.setEnabled(false);
&nbsp; &nbsp; &nbsp; &nbsp; cancela.addActionListener(new java.awt.event.ActionListener() {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void actionPerformed(java.awt.event.ActionEvent evt) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cancelaActionPerformed(evt);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; });

&nbsp; &nbsp; &nbsp; &nbsp; javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
&nbsp; &nbsp; &nbsp; &nbsp; getContentPane().setLayout(layout);
&nbsp; &nbsp; &nbsp; &nbsp; layout.setHorizontalGroup(
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGroup(layout.createSequentialGroup()
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGap(25, 25, 25)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(jLabel3)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(jLabel4)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(jLabel2)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(jLabel1))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGap(29, 29, 29)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(id, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(peso, javax.swing.GroupLayout.Alignment.LEADING)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(preco, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 84, Short.MAX_VALUE))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGap(18, 18, 18)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(status, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(nome, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 264, javax.swing.GroupLayout.PREFERRED_SIZE))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGap(32, 32, 32)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(primeiro, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(ultimo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGroup(layout.createSequentialGroup()
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(anterior, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(proximo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGap(4, 4, 4)))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGap(26, 26, 26)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(cancela)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(salvar)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(editar)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(mais)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(deletar))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addContainerGap())
&nbsp; &nbsp; &nbsp; &nbsp; );
&nbsp; &nbsp; &nbsp; &nbsp; layout.setVerticalGroup(
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGroup(layout.createSequentialGroup()
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addContainerGap()
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGroup(layout.createSequentialGroup()
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(id, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(jLabel1))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGap(18, 18, 18)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(nome, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(jLabel2))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGap(18, 18, 18)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(preco, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(jLabel3))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGap(18, 18, 18)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(peso, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(jLabel4)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(status, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGroup(layout.createSequentialGroup()
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(primeiro)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(mais))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGap(18, 18, 18)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(anterior)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(deletar))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGap(18, 18, 18)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(proximo)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(editar))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGap(18, 18, 18)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(ultimo)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(salvar))))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addGap(18, 18, 18)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addComponent(cancela)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addContainerGap(26, Short.MAX_VALUE))
&nbsp; &nbsp; &nbsp; &nbsp; );

&nbsp; &nbsp; &nbsp; &nbsp; pack();
&nbsp; &nbsp; }// &lt;/editor-fold&gt;//GEN-END:initComponents
&nbsp; &nbsp; public Connection con = null;
&nbsp; &nbsp; private Statement select = null;
&nbsp; &nbsp; private PreparedStatement insert = null;
&nbsp; &nbsp;// private Statement delete = null;
&nbsp; &nbsp; //private Statement edit = null;
&nbsp; &nbsp; private ResultSet registros = null;
&nbsp; &nbsp; private int action;
&nbsp; &nbsp;

&nbsp; &nbsp;
&nbsp; &nbsp; private void primeiroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_primeiroActionPerformed
&nbsp; &nbsp; &nbsp; &nbsp; try {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; registros.first();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exibe();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message(9);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; habilitar();
&nbsp; &nbsp; &nbsp; &nbsp; } catch (SQLException ex) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;message(5);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;JOptionPane.showMessageDialog(null, ex.getMessage());
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; }//GEN-LAST:event_primeiroActionPerformed

&nbsp; &nbsp; private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened

&nbsp; &nbsp; &nbsp; &nbsp; cancela.setVisible(false);
&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; // TODO add your handling code here:
&nbsp; &nbsp; &nbsp; &nbsp; // Conecta o banco de dados
&nbsp; &nbsp; &nbsp; &nbsp; try {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Class.forName("org.gjt.mm.mysql.Driver").newInstance();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/teste?autoReconnect=true","root", "");

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(!con.isClosed())
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message(6);

&nbsp; &nbsp; &nbsp; &nbsp; } catch(Exception e) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message(3);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOptionPane.showMessageDialog(null, e.getMessage());
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; // prepara a consulta
&nbsp; &nbsp; &nbsp; &nbsp; try {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; select = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
&nbsp; &nbsp; &nbsp; &nbsp; } catch (SQLException ex) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message(5);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOptionPane.showMessageDialog(null, ex.getMessage());
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; try {
&nbsp; &nbsp; &nbsp; &nbsp; // executando a consulta
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; registros = select.executeQuery("select * from produtos where ativo = 1");
&nbsp; &nbsp; &nbsp; &nbsp; } catch (SQLException ex) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message(7);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOptionPane.showMessageDialog(null, ex.getMessage());
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; try {
&nbsp; &nbsp; &nbsp; &nbsp; // carregando registros
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; registros.first();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exibe();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; habilitar();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; } catch (SQLException ex) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message(2);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOptionPane.showMessageDialog(null, ex.getMessage());
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; }//GEN-LAST:event_formWindowOpened

&nbsp; &nbsp; private void idActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_idActionPerformed
&nbsp; &nbsp; &nbsp; &nbsp; // TODO add your handling code here:
&nbsp; &nbsp; }//GEN-LAST:event_idActionPerformed

&nbsp; &nbsp; private void ultimoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ultimoActionPerformed
&nbsp; &nbsp; &nbsp; &nbsp; try {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; registros.last();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exibe();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message(9);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; habilitar();
&nbsp; &nbsp; &nbsp; &nbsp; } catch (SQLException ex) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message(5);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOptionPane.showMessageDialog(null, ex.getMessage());
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; }//GEN-LAST:event_ultimoActionPerformed

&nbsp; &nbsp; private void anteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_anteriorActionPerformed
&nbsp; &nbsp; &nbsp; &nbsp; try {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; registros.previous();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exibe();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message(9);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; habilitar();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; } catch (SQLException ex) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message(5);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOptionPane.showMessageDialog(null, ex.getMessage());
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; }//GEN-LAST:event_anteriorActionPerformed

&nbsp; &nbsp; private void proximoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_proximoActionPerformed
&nbsp; &nbsp; &nbsp; &nbsp;try {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;registros.next();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;exibe();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;message(9);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;habilitar();
&nbsp; &nbsp; &nbsp; &nbsp; } catch (SQLException ex) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;message(5);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOptionPane.showMessageDialog(null, ex.getMessage());
&nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; }//GEN-LAST:event_proximoActionPerformed

&nbsp; &nbsp; private void salvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salvarActionPerformed
&nbsp; &nbsp; &nbsp; &nbsp; // TODO add your handling code here:
&nbsp; &nbsp; &nbsp; &nbsp; if (action == 1){
&nbsp; &nbsp; &nbsp; &nbsp; update();
&nbsp; &nbsp; &nbsp; &nbsp; cancelar();
&nbsp; &nbsp; &nbsp; &nbsp; }else
&nbsp; &nbsp; &nbsp; &nbsp; insere();
&nbsp; &nbsp; &nbsp; &nbsp; cancelar();
&nbsp; &nbsp; }//GEN-LAST:event_salvarActionPerformed

&nbsp; &nbsp; private void deletarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deletarActionPerformed
&nbsp; &nbsp; &nbsp; &nbsp; // TODO add your handling code here:
&nbsp; &nbsp; &nbsp; &nbsp; int result = JOptionPane.showConfirmDialog(null,"Deseja Excluir ? ","Excluir",JOptionPane.YES_OPTION);
&nbsp; &nbsp; &nbsp; &nbsp; if (result == JOptionPane.YES_OPTION){
&nbsp; &nbsp; &nbsp; &nbsp; delete();
&nbsp; &nbsp; &nbsp; &nbsp;}
&nbsp; &nbsp; }//GEN-LAST:event_deletarActionPerformed

&nbsp; &nbsp; private void editarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editarActionPerformed
&nbsp; &nbsp; &nbsp; &nbsp; action = 1; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; editar();
&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; // TODO add your handling code here:
&nbsp; &nbsp; }//GEN-LAST:event_editarActionPerformed

&nbsp; &nbsp; private void cancelaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelaActionPerformed
&nbsp; &nbsp; &nbsp; &nbsp; cancelar();
&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; // TODO add your handling code here:
&nbsp; &nbsp; }//GEN-LAST:event_cancelaActionPerformed

&nbsp; &nbsp; private void maisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_maisActionPerformed
&nbsp; &nbsp; &nbsp; &nbsp; novo();
&nbsp; &nbsp; &nbsp; &nbsp; action = 0;
&nbsp; &nbsp; &nbsp; &nbsp; // TODO add your handling code here:
&nbsp; &nbsp; }//GEN-LAST:event_maisActionPerformed

&nbsp; &nbsp; /**
&nbsp; &nbsp; &nbsp;* @param args the command line arguments
&nbsp; &nbsp; &nbsp;*/
&nbsp; &nbsp;
&nbsp; &nbsp; public static void main(String args[]) {
&nbsp; &nbsp; &nbsp; &nbsp; java.awt.EventQueue.invokeLater(new Runnable() {

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void run() {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new Produtos().setVisible(true);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; });
&nbsp; &nbsp; }
&nbsp; &nbsp; // Variables declaration - do not modify//GEN-BEGIN:variables
&nbsp; &nbsp; private javax.swing.JButton anterior;
&nbsp; &nbsp; private javax.swing.JButton cancela;
&nbsp; &nbsp; private javax.swing.JButton deletar;
&nbsp; &nbsp; private javax.swing.JButton editar;
&nbsp; &nbsp; private javax.swing.JTextField id;
&nbsp; &nbsp; private javax.swing.JLabel jLabel1;
&nbsp; &nbsp; private javax.swing.JLabel jLabel2;
&nbsp; &nbsp; private javax.swing.JLabel jLabel3;
&nbsp; &nbsp; private javax.swing.JLabel jLabel4;
&nbsp; &nbsp; private javax.swing.JButton mais;
&nbsp; &nbsp; private javax.swing.JTextField nome;
&nbsp; &nbsp; private javax.swing.JTextField peso;
&nbsp; &nbsp; private javax.swing.JTextField preco;
&nbsp; &nbsp; private javax.swing.JButton primeiro;
&nbsp; &nbsp; private javax.swing.JButton proximo;
&nbsp; &nbsp; private javax.swing.JButton salvar;
&nbsp; &nbsp; private javax.swing.JLabel status;
&nbsp; &nbsp; private javax.swing.JButton ultimo;
&nbsp; &nbsp; // End of variables declaration//GEN-END:variables

public void exibe(){
&nbsp; &nbsp; try {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id.setText(registros.getString("id"));
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nome.setText(registros.getString("nome"));
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; preco.setText(registros.getString("preco"));
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; peso.setText(registros.getString("peso"));
&nbsp; &nbsp; }
&nbsp; &nbsp; catch (SQLException e){
&nbsp; &nbsp; &nbsp; &nbsp; message(2);
&nbsp; &nbsp; &nbsp; &nbsp; JOptionPane.showMessageDialog(null, e.getMessage());
&nbsp; &nbsp; }
}
public void insere(){
&nbsp; &nbsp; &nbsp; &nbsp; try {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; insert = (PreparedStatement) con.prepareStatement("insert into produtos (nome, preco, peso, ativo) values ( ?, ?, ?, ?)");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //insert.setString(1, "default");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; insert.setString(1, nome.getText());
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; insert.setFloat(2, Float.parseFloat(preco.getText()));
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; insert.setFloat(3, Float.parseFloat(peso.getText()));
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; insert.setInt(4, 1);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; insert.execute();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; registros = select.executeQuery("select * from produtos where ativo = 1");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exibe();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message(4);
&nbsp; &nbsp; &nbsp; &nbsp; } catch (SQLException ex) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;message(1);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;JOptionPane.showMessageDialog(null, ex.getMessage()); &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; }
}
public void update(){
&nbsp; &nbsp; &nbsp; &nbsp; try {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; insert = (PreparedStatement) con.prepareStatement("update produtos set nome = ?, preco = ?, peso = ? where id ="+id.getText());
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; insert.setString(1, nome.getText());
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; insert.setFloat(2, Float.parseFloat(preco.getText()));
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; insert.setFloat(3, Float.parseFloat(peso.getText()));
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; insert.executeUpdate();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; registros = select.executeQuery("select * from produtos where ativo = 1");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message(4);
&nbsp; &nbsp; &nbsp; &nbsp; } catch (SQLException ex) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;message(1);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;JOptionPane.showMessageDialog(null, ex.getMessage()); &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; }
}

public void delete(){
&nbsp; &nbsp; &nbsp; &nbsp; try {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; insert = (PreparedStatement) con.prepareStatement("update produtos set ativo = ? where id = "+id.getText());
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; insert.setInt(1, 0);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; insert.executeUpdate();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; registros = select.executeQuery("select * from produtos where ativo = 1");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; registros.next();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exibe();
&nbsp; &nbsp; &nbsp; &nbsp; } catch (SQLException ex) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message(1);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOptionPane.showMessageDialog(null, ex.getMessage());
&nbsp; &nbsp; &nbsp; &nbsp; }
}
public void message(int op){
&nbsp; &nbsp; if (op == 1){
&nbsp; &nbsp; &nbsp; &nbsp; status.setText("Erro ao salvar!");
&nbsp; &nbsp; &nbsp; &nbsp; status.setForeground(Color.red);
&nbsp; &nbsp; }else if (op == 2){
&nbsp; &nbsp; &nbsp; &nbsp; status.setText("Falha ao carregar!");
&nbsp; &nbsp; &nbsp; &nbsp; status.setForeground(Color.red);
&nbsp; &nbsp; }else if (op == 7){
&nbsp; &nbsp; &nbsp; &nbsp; status.setText("Falha na consulta!");
&nbsp; &nbsp; &nbsp; &nbsp; status.setForeground(Color.red);
&nbsp; &nbsp; }else if (op == 3){
&nbsp; &nbsp; &nbsp; &nbsp; status.setText("Deu Merda...");
&nbsp; &nbsp; &nbsp; &nbsp; status.setForeground(Color.red);
&nbsp; &nbsp; }else if (op == 4){
&nbsp; &nbsp; &nbsp; &nbsp; status.setText("Sucesso");
&nbsp; &nbsp; &nbsp; &nbsp; status.setForeground(Color.green);
&nbsp; &nbsp; }else if (op == 5){
&nbsp; &nbsp; &nbsp; &nbsp; status.setText("Não permitido!");
&nbsp; &nbsp; &nbsp; &nbsp; status.setForeground(Color.red);
&nbsp; &nbsp; }else if (op == 6){
&nbsp; &nbsp; &nbsp; &nbsp; status.setText("Conectado!");
&nbsp; &nbsp; &nbsp; &nbsp; status.setForeground(Color.green);
&nbsp; &nbsp; }else if (op == 8){
&nbsp; &nbsp; &nbsp; &nbsp; status.setText("Fim!");
&nbsp; &nbsp; &nbsp; &nbsp; status.setForeground(Color.blue);
&nbsp; &nbsp; }else if (op == 9){
&nbsp; &nbsp; &nbsp; &nbsp; status.setText("Inicio!");
&nbsp; &nbsp; &nbsp; &nbsp; status.setForeground(Color.blue);
&nbsp; &nbsp; }
}
public void editar(){
&nbsp; &nbsp;primeiro.setEnabled(false);
&nbsp; &nbsp;ultimo.setEnabled(false);
&nbsp; &nbsp;anterior.setEnabled(false);
&nbsp; &nbsp;proximo.setEnabled(false);
&nbsp; &nbsp;mais.setEnabled(false);
&nbsp; &nbsp;deletar.setEnabled(false);
&nbsp; &nbsp;editar.setEnabled(false);
&nbsp; &nbsp;salvar.setEnabled(true);
&nbsp; &nbsp;cancela.setVisible(true);
&nbsp; &nbsp;cancela.setEnabled(true);
&nbsp; &nbsp;id.setEnabled(false);
}
public void cancelar(){
&nbsp; &nbsp;primeiro.setEnabled(true);
&nbsp; &nbsp;ultimo.setEnabled(true);
&nbsp; &nbsp;anterior.setEnabled(true);
&nbsp; &nbsp;proximo.setEnabled(true);
&nbsp; &nbsp;mais.setEnabled(true);
&nbsp; &nbsp;deletar.setEnabled(true);
&nbsp; &nbsp;editar.setEnabled(true);
&nbsp; &nbsp;salvar.setEnabled(false);
&nbsp; &nbsp;cancela.setVisible(false);
&nbsp; &nbsp;cancela.setEnabled(false);
&nbsp; &nbsp;id.setEnabled(true);
}
public void novo(){
&nbsp; &nbsp;primeiro.setEnabled(false);
&nbsp; &nbsp;ultimo.setEnabled(false);
&nbsp; &nbsp;anterior.setEnabled(false);
&nbsp; &nbsp;proximo.setEnabled(false);
&nbsp; &nbsp;mais.setEnabled(false);
&nbsp; &nbsp;deletar.setEnabled(false);
&nbsp; &nbsp;editar.setEnabled(false);
&nbsp; &nbsp;salvar.setEnabled(true);
&nbsp; &nbsp;cancela.setVisible(true);
&nbsp; &nbsp;cancela.setEnabled(true);
&nbsp; &nbsp;id.setText("");
&nbsp; &nbsp;nome.setText("");
&nbsp; &nbsp;preco.setText("");
&nbsp; &nbsp;peso.setText("");
&nbsp; &nbsp;id.setEnabled(false);
}
public void habilitar(){
&nbsp; &nbsp; &nbsp; &nbsp; try {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; primeiro.setEnabled(!registros.isFirst());
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ultimo.setEnabled(!registros.isLast());
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; anterior.setEnabled(!registros.isFirst());
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proximo.setEnabled(!registros.isLast());
&nbsp; &nbsp; &nbsp; &nbsp; } catch (SQLException ex) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message(7);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOptionPane.showMessageDialog(null, ex.getMessage());
&nbsp; &nbsp; &nbsp; &nbsp; }
}
}