Jcombobox e access

2 respostas
C

Olá,

Estou tendo dificuldade em fazer uma consulta no banco de dados da seguinte maneira. tenho um Jcombobox onde quero que o mesmo me traga uma determinada informação que esta no meu banco de dados access, sendo que não estou sabendo como coloco o comando para ele consultar no banco

apenas quero que no jcombobox ele me traga os dados que ja esta cadastrado no banco. vocês saberiam como eu crio esta consulta Obs:. os dados do banco e nome ( letras ).

Desde Já fico grato com sua ajuda

2 Respostas

C

Coloca o seu código pra gente dar uma olhada, ok ?

C

package apresentacao;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.Statement;

import java.text.ParseException;

import javax.swing.JOptionPane;

import negocio.Produto;

import persistencia.ProdutoBD;

/**
*

  • @author Douglas Coé
    */
    public class Movimentacao extends javax.swing.JFrame {

    /** Creates new form Movimentacao */
    
    public Movimentacao() {
    
    initComponents();
    
    }
    

    /** This method is called from within the constructor to

    • initialize the form.

    • WARNING: Do NOT modify this code. The content of this method is

    • always regenerated by the Form Editor.
      
      */
      
      // <editor-fold defaultstate=“collapsed” desc=" Generated Code ">//GEN-BEGIN:initComponents
      
      private void initComponents() {
      
      Titulo = new javax.swing.JLabel();
      
      Nom = new javax.swing.JLabel();
      
      Quant = new javax.swing.JLabel();
      
      Set = new javax.swing.JLabel();
      
      Tipo = new javax.swing.JLabel();
      
      Nome = new javax.swing.JComboBox();
      
      txtQuantidade = new javax.swing.JTextField();
      
      jButton1 = new javax.swing.JButton();
      
      Setor = new javax.swing.JComboBox();
      
      TipoOp = new javax.swing.JComboBox();
      

      setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
      Titulo.setText(" Movimenta\u00e7\u00e3o ");

      Nom.setText(" Nome :");

      Quant.setText(“Quantidade :”);

      Set.setText(“Setor :”);

      Tipo.setText(“Tipo Opera\u00e7\u00e3o”);

      Nome.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      NomeActionPerformed(evt);
      
      }
      
      });
      
      txtQuantidade.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      txtquantidadeActionPerformed(evt);
      
      }
      
      });
      
      jButton1.setText(Cadastrar);
      
      jButton1.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jButton1ActionPerformed(evt);
      
      }
      
      });
      
      TipoOp.setModel(new javax.swing.DefaultComboBoxModel(new String[] { Entrada, Saida }));
      
      TipoOp.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      TipoOpActionPerformed(evt);
      
      }
      
      });
      
      org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
      
      getContentPane().setLayout(layout);
      
      layout.setHorizontalGroup(
      
      layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
      
      .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
      
      .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
      
      .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
      
      .addContainerGap()
      
      .add(Tipo)
      
      .add(16, 16, 16)
      
      .add(TipoOp, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 69, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
      
      .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 114, Short.MAX_VALUE)
      
      .add(jButton1))
      
      .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
      
      .add(149, 149, 149)
      
      .add(Titulo))
      
      .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
      
      .addContainerGap()
      
      .add(Nom, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 54, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
      
      .add(32, 32, 32)
      
      .add(Nome, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 266, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
      
      .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
      
      .addContainerGap()
      
      .add(Set)
      
      .add(53, 53, 53)
      
      .add(Setor, 0, 266, Short.MAX_VALUE)))
      
      .add(31, 31, 31))
      
      .add(layout.createSequentialGroup()
      
      .addContainerGap()
      
      .add(Quant, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 66, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
      
      .add(20, 20, 20)
      
      .add(txtQuantidade, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 37, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
      
      .addContainerGap(260, Short.MAX_VALUE))
      
      );
      
      layout.setVerticalGroup(
      
      layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
      
      .add(layout.createSequentialGroup()
      
      .add(5, 5, 5)
      
      .add(Titulo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
      
      .add(14, 14, 14)
      
      .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
      
      .add(Nome, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
      
      .add(Nom, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 18, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
      
      .add(15, 15, 15)
      
      .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
      
      .add(txtQuantidade, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
      
      .add(Quant))
      
      .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
      
      .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
      
      .add(Set)
      
      .add(Setor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
      
      .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 21, Short.MAX_VALUE)
      
      .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
      
      .add(TipoOp, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
      
      .add(Tipo)
      
      .add(jButton1))
      
      .add(22, 22, 22))
      
      );
      
      pack();
      
      }// </editor-fold>//GEN-END:initComponents
      

    private void NomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NomeActionPerformed
    // Select Do Nome

Aqui eu tenho que colocar o codigo para acessar o access para me retornar os nomes do campo prodnome

OBS coloquei para so carregar no momento que se abre a janela

}//GEN-LAST:event_NomeActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

// TODO add your handling code here:
}//GEN-LAST:event_jButton1ActionPerformed

private void TipoOpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TipoOpActionPerformed

// TODO add your handling code here:
}//GEN-LAST:event_TipoOpActionPerformed

private void txtquantidadeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtquantidadeActionPerformed

// TODO add your handling code here:

}//GEN-LAST:event_txtquantidadeActionPerformed

/**
 * @param args the command line arguments
 */
public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new CadastroProduto().setVisible(true);
        }
    });
}

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel Nom;
private javax.swing.JComboBox Nome;
private javax.swing.JLabel Quant;
private javax.swing.JLabel Set;
private javax.swing.JComboBox Setor;
private javax.swing.JLabel Tipo;
private javax.swing.JComboBox TipoOp;
private javax.swing.JLabel Titulo;
private javax.swing.JButton jButton1;
private javax.swing.JTextField txtQuantidade;
// End of variables declaration//GEN-END:variables
}

Criado 13 de junho de 2006
Ultima resposta 16 de jun. de 2006
Respostas 2
Participantes 2