Boa noite pessoal,
Sou iniciante,
Como posso resolver esse erro?
exception java.sql.SQLException is never thrown in body of corresponding try statement
Boa noite pessoal,
Sou iniciante,
Como posso resolver esse erro?
exception java.sql.SQLException is never thrown in body of corresponding try statement
Posta o código
package Cadastro;
import Utilitarios.conexao;
import java.sql.SQLException;
import javax.swing.JOptionPane;
public class Vestuario extends javax.swing.JFrame {
conexao conecta_vestuario;
public Vestuario() {
initComponents();
conecta_vestuario = new conexao();
conecta_vestuario.conecta();
conecta_vestuario.executeSQL("select * from vestuario");
try
{
campo_codigo.setText(conecta_vestuario.getString("vest_codigo"));
Campo_peca.setText(conecta_vestuario.getString("vest_peca"));
}
catch(SQLException e)
{
JOptionPane.showMessageDialog(null, "Não localizou dados " + e);
}
}
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
campo_codigo = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
Campo_peca = new javax.swing.JTextField();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jButton7 = new javax.swing.JButton();
jButton8 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Cadastro de Vestu\u00e1rio");
jLabel1.setBackground(new java.awt.Color(52, 120, 180));
jLabel1.setFont(new java.awt.Font("Arial", 1, 18));
jLabel1.setForeground(new java.awt.Color(52, 120, 180));
jLabel1.setText("CADASTRO DE VESTU\u00c1RIO");
jLabel2.setFont(new java.awt.Font("Arial", 1, 12));
jLabel2.setText("PE\u00c7A:");
campo_codigo.setToolTipText("Campo de preenchimento autom\u00e1tico");
jButton1.setIcon(new javax.swing.ImageIcon("C:\\Pais & Filhos\\Imagens\\Novo.jpeg"));
jButton1.setToolTipText("Novo registro");
jButton2.setIcon(new javax.swing.ImageIcon("C:\\Pais & Filhos\\Imagens\\Alterar.jpeg"));
jButton2.setToolTipText("Alterar registro");
jButton3.setIcon(new javax.swing.ImageIcon("C:\\Pais & Filhos\\Imagens\\Salvar.jpeg"));
jButton3.setToolTipText("Salvar registro");
jButton4.setIcon(new javax.swing.ImageIcon("C:\\Pais & Filhos\\Imagens\\Deletar.jpeg"));
jButton4.setToolTipText("Excluir registro");
jLabel3.setFont(new java.awt.Font("Arial", 1, 12));
jLabel3.setText("C\u00d3DIGO:");
Campo_peca.setToolTipText("Preencha a pe\u00e7a do vestu\u00e1rio. Ex.: Cal\u00e7a, camisa, etc.");
jButton5.setIcon(new javax.swing.ImageIcon("C:\\Pais & Filhos\\Imagens\\Primeiro.png"));
jButton5.setToolTipText("Volta ao primeiro registro");
jButton6.setIcon(new javax.swing.ImageIcon("C:\\Pais & Filhos\\Imagens\\Voltar.png"));
jButton6.setToolTipText("Volta ao registro anterior");
jButton7.setIcon(new javax.swing.ImageIcon("C:\\Pais & Filhos\\Imagens\\Proximo.png"));
jButton7.setToolTipText("Avan\u00e7a para o pr\u00f3ximo registro");
jButton8.setIcon(new javax.swing.ImageIcon("C:\\Pais & Filhos\\Imagens\\Ultimo.png"));
jButton8.setToolTipText("Avan\u00e7a para o \u00faltimo registro");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(54, 54, 54)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Campo_peca, javax.swing.GroupLayout.DEFAULT_SIZE, 394, Short.MAX_VALUE)
.addComponent(campo_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(64, 64, 64))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(192, Short.MAX_VALUE)
.addComponent(jLabel1)
.addGap(129, 129, 129))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(31, 31, 31)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(campo_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(34, 34, 34)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2)
.addComponent(Campo_peca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(46, 46, 46)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton5)
.addComponent(jButton6)
.addComponent(jButton7)
.addComponent(jButton8)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jButton4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addContainerGap(60, Short.MAX_VALUE))
);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-580)/2, (screenSize.height-349)/2, 580, 349);
}// </editor-fold>
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Vestuario().setVisible(true);
}
});
}
private javax.swing.JTextField Campo_peca;
private javax.swing.JTextField campo_codigo;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JButton jButton8;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
}
Você não utilizou a classe ResultSet. Nela que você consegue realmente obter o valor das pesquisas, ela é usada junto com o while. existem varios exemplos na internet de consulta do SQL, da uma olhada e modifica para seu uso.
Você pôs um catch SQLException
em um código que não lança SQLException
.