Pessoal, no codigo anexo, nao consigo salvar, alguem pode analisar e me dizer o q esta acontecendo, alias só o botao excluir funcionou corretamente, pra salvar o erro é “erro cmdo sql - No suitable driver”
agradeço quem puder ajudar
import java.sql.;
import javax.swing.;
/*
- Matricula.java
- Created on 24 de Julho de 2006, 12:34
*/
/**
*
-
@author Julio
*/
public class Matricula extends javax.swing.JFrame {/** Creates new form Matricula */
public Matricula() {
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 ">
private void initComponents() {
jLabel_consulta = new javax.swing.JLabel();
jTextField_consulta = new javax.swing.JTextField();
jLabel_nome = new javax.swing.JLabel();
jTextField_nome = new javax.swing.JTextField();
jLabel_matricula = new javax.swing.JLabel();
jTextField_matricula = new javax.swing.JTextField();
jButton_salvar = new javax.swing.JButton();
jButton_alterar = new javax.swing.JButton();
jButton_excluir = new javax.swing.JButton();
jButton_consultar = new javax.swing.JButton();setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel_consulta.setText(“Consulta”);jTextField_consulta.setName(“consulta”);
jLabel_nome.setText(“Nome”);
jTextField_nome.setName(“nome”);
jLabel_matricula.setText(“Matricula”);
jTextField_matricula.setName(“matricula”);
jButton_salvar.setText(“salvar”);
jButton_salvar.setName(“salvar”);
jButton_salvar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton_salvarActionPerformed(evt);
}
});jButton_alterar.setText(“alterar”);
jButton_alterar.setName(“alterar”);
jButton_alterar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton_alterarActionPerformed(evt);
}
});jButton_excluir.setText(“excluir”);
jButton_excluir.setName(“excluir”);
jButton_excluir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton_excluirActionPerformed(evt);
}
});jButton_consultar.setText(“consultar”);
jButton_consultar.setName(“consultar”);
jButton_consultar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton_consultarActionPerformed(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(layout.createSequentialGroup()
.add(23, 23, 23)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel_consulta)
.add(jLabel_nome)
.add(jLabel_matricula))
.add(13, 13, 13)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(jTextField_consulta, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 203, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jTextField_nome, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE)
.add(jTextField_matricula))
.addContainerGap(96, Short.MAX_VALUE))
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jButton_salvar)
.add(21, 21, 21)
.add(jButton_alterar)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 43, Short.MAX_VALUE)
.add(jButton_excluir)
.add(34, 34, 34)
.add(jButton_consultar)
.add(22, 22, 22))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(31, 31, 31)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel_consulta)
.add(jTextField_consulta, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(31, 31, 31)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel_matricula)
.add(jTextField_matricula, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(14, 14, 14)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel_nome)
.add(jTextField_nome, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 93, Short.MAX_VALUE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jButton_salvar)
.add(jButton_alterar)
.add(jButton_consultar)
.add(jButton_excluir))
.add(48, 48, 48))
);
pack();
}// </editor-fold>
private void jButton_excluirActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try // tratamento de erros
{
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
Connection con = DriverManager.getConnection(“jdbc:odbc:matricula”,"","");
Statement stmt = con.createStatement(); // objeto comdo sql
String ExNome = jTextField_consulta.getText();
int registro = stmt.executeUpdate(“delete from matricula where nome = '”+ExNome+"’");
if (registro!=0)
JOptionPane.showMessageDialog(this,“dados excluidos”);
else
JOptionPane.showMessageDialog(this,“dados nao exluidos”);
stmt.close();
con.close();
}catch(SQLException e ) // trata erros { JOptionPane.showMessageDialog(this,"erro comdo sql " + e.getMessage()); } catch(ClassNotFoundException e) { JOptionPane.showMessageDialog(this,"driver nao encontrado"); }
}
private void jButton_alterarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try // tratamento de erros
{
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
Connection con = DriverManager.getConnection(“jdbc:odbc:matricula”,"","");
Statement stmt = con.createStatement(); // objeto comdo sql
String ConsNome = jTextField_consulta.getText();
int CadMat = Integer.parseInt(jTextField_matricula.getText());
String CadNome = jTextField_nome.getText();
int registro = stmt.executeUpdate(“update matricula set nome = '” + CadNome + “’, matricula=’” + CadMat+ “’ where nome =’” + ConsNome + " ’ " );
if(registro!=0)
JOptionPane.showMessageDialog(this, “dados nao alterados”);
else
JOptionPane.showMessageDialog(this,“dados nao alterados”);
stmt.close();
con.close(); // fechando conexao com bd
}catch(SQLException e)// trata erros { JOptionPane.showMessageDialog(this,"erro comdo sql" + e.getMessage() ); } catch(ClassNotFoundException e) { JOptionPane.showMessageDialog(this,"driver nao encontrado"); }
}
private void jButton_consultarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
boolean consulta = true; //variavel auxiliar pra verificar se houve sucesso na consultatry // tratamento de erros { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");// busca driver Connection con=DriverManager.getConnection("jdbc:odbc:matricula","",""); Statement stmt=con.createStatement();//objeto comdo sql String ConsNome = jTextField_consulta.getText(); ResultSet RS = stmt.executeQuery( "Select *from matricula where nome =' " + ConsNome + "'"); while(RS.next()) { int Mat=RS.getInt("matricula"); jTextField_matricula.setText(String.valueOf("Mat")); jTextField_nome.setText(String.valueOf("nome")); consulta=false; JOptionPane.showMessageDialog(this,"Dados encontrado"); if(consulta) JOptionPane.showMessageDialog(this,"Dados nao encontrados!"); RS.close(); stmt.close(); con.close(); // fechando conexoes } } catch(SQLException e) //tratando erros { JOptionPane.showMessageDialog(this,"erro no comando sql " + e.getMessage()); } catch(ClassNotFoundException e) { JOptionPane.showMessageDialog(this,"driver nao encontrado"); }
}
private void jButton_salvarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try // tratamento de erros
{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");// busca driver Connection con = DriverManager.getConnection("Jodbc:odbc:matricula","","" ); //conecta no bd Statement stmt = con.createStatement(); // objeto comando sql String CadNome=jTextField_nome.getText();// obtem o nome digitado int CadMat = Integer.parseInt(jTextField_matricula.getText()); stmt.executeUpdate("insert into matricula(matricula,nome) values(' " + CadMat + " ',' " +CadNome + " ' )"); JOptionPane.showMessageDialog(this,"dados salvos"); con.close();//fecha conexao com bd } catch(SQLException e)// trata os erros { JOptionPane.showMessageDialog(this,"Erro cmd sql - " + e.getMessage()); } catch(ClassNotFoundException e) { JOptionPane.showMessageDialog(this,"driver nao encontrado"); }
}
/**
-
@param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Matricula().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton_alterar;
private javax.swing.JButton jButton_consultar;
private javax.swing.JButton jButton_excluir;
private javax.swing.JButton jButton_salvar;
private javax.swing.JLabel jLabel_consulta;
private javax.swing.JLabel jLabel_matricula;
private javax.swing.JLabel jLabel_nome;
private javax.swing.JTextField jTextField_consulta;
private javax.swing.JTextField jTextField_matricula;
private javax.swing.JTextField jTextField_nome;
// End of variables declaration -
}