Com.mysql.jdbc.Driver(Erro ao incluir no Netbeans)

1 resposta
E
  • conexao.java
  • Created on 7 de Novembro de 2006, 23:31
  • To change this template, choose Tools | Template Manager
  • and open the template in the editor.
    */

package apresentacao;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

/**
*

  • @author Evandro
    */
    public class conexao {

    private static Connection conn;
    
    private static final String URL = jdbc:mysql://localhost:3306/universidade”;
    
    private static final String DRIVER = com.mysql.jdbc.Driver;
    
    private static final String USUARIO = root;
    
    private static final String PASSWORD = “”;
    
    /** Creates a new instance of conexao */
    
    public static Connection abreConexao() throws SQLException {
    
    try {
    
    if (conn == null) {
    
    Class.forName(DRIVER);
    
    conn = DriverManager.getConnection(URL, USUARIO, PASSWORD);
    
    }
         return conn;
     } catch (ClassNotFoundException e) {
         throw new SQLException(e.getMessage());
     }
    

    }

}

package apresentacao;

import java.sql.Connection;

import java.sql.SQLException;

public class FrmRegistrarCompra extends javax.swing.JInternalFrame {

private static FrmRegistrarCompra instance = null;

private FrmRegistrarCompra() {
    initComponents();
}

public static FrmRegistrarCompra getInstance(){
    if (instance == null)
        instance = new FrmRegistrarCompra();
    return instance;
}

// <editor-fold defaultstate="collapsed" desc=" Generated Code ">                          
private void initComponents() {
    jLabel7 = new javax.swing.JLabel();
    jFormattedTextFieldValorNota = new javax.swing.JFormattedTextField();
    jLabel1 = new javax.swing.JLabel();
    jLabel8 = new javax.swing.JLabel();
    jFormattedTextFieldData = new javax.swing.JFormattedTextField();
    jFormattedTextFieldCodigo = new javax.swing.JFormattedTextField();
    jButtonClose = new javax.swing.JButton();
    jButton1 = new javax.swing.JButton();

    setClosable(true);
    addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
        public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
        }
        public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            formInternalFrameClosed(evt);
        }
        public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
        }
        public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
        }
        public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
        }
        public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
        }
        public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
        }
    });

    jLabel7.setText("Valor da Nota");

    jFormattedTextFieldValorNota.setFocusLostBehavior(javax.swing.JFormattedTextField.PERSIST);
    jFormattedTextFieldValorNota.setFont(new java.awt.Font("Tahoma", 0, 11));

    jLabel1.setText("C\u00f3digo do Fornecedor");

    jLabel8.setText("Data de Emiss\u00e3o");

    jFormattedTextFieldData.setFocusLostBehavior(javax.swing.JFormattedTextField.PERSIST);
    jFormattedTextFieldData.setFont(new java.awt.Font("Tahoma", 0, 11));

    jButtonClose.setText("Close");
    jButtonClose.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButtonCloseActionPerformed(evt);
        }
    });

    jButton1.setText("jButton1");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton1ActionPerformed(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()
            .addContainerGap()
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .add(jLabel1)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(jFormattedTextFieldCodigo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 69, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(layout.createSequentialGroup()
                    .add(jLabel7)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(jFormattedTextFieldValorNota, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(layout.createSequentialGroup()
                    .add(jLabel8)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(jFormattedTextFieldData, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                    .add(jButton1)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 60, Short.MAX_VALUE)
                    .add(jButtonClose)))
            .addContainerGap())
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(layout.createSequentialGroup()
            .addContainerGap()
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(jLabel1)
                .add(jFormattedTextFieldCodigo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(jLabel7)
                .add(jFormattedTextFieldValorNota, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(jLabel8)
                .add(jFormattedTextFieldData, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(jButtonClose)
                .add(jButton1))
            .addContainerGap(14, Short.MAX_VALUE))
    );
    pack();
}// </editor-fold>                        

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

            try{

                Connection conn = conexao.abreConexao();
                String sql="insert into clientes (nome) values (?)";
                java.sql.PreparedStatement pStmt = conn.prepareStatement(sql);
                pStmt.setString(1,"teste");
                pStmt.executeUpdate();
    
            }
            catch (SQLException e) {
            System.out.println(e.getMessage());
            
            
    }

// TODO add your handling code here:
}

private void formInternalFrameClosed(javax.swing.event.InternalFrameEvent evt) {                                         
    this.instance=null;
}                                        

private void jButtonCloseActionPerformed(java.awt.event.ActionEvent evt) {                                             
    this.dispose();
}                                            


// Variables declaration - do not modify                     
private javax.swing.JButton jButton1;
private javax.swing.JButton jButtonClose;
private javax.swing.JFormattedTextField jFormattedTextFieldCodigo;
private javax.swing.JFormattedTextField jFormattedTextFieldData;
private javax.swing.JFormattedTextField jFormattedTextFieldValorNota;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
// End of variables declaration

}
No rodape, esta dando o seguinte erro:

init:
deps-jar:
compile:
run:
com.mysql.jdbc.Driver
com.mysql.jdbc.Driver
com.mysql.jdbc.Driver
com.mysql.jdbc.Driver
BUILD SUCCESSFUL (total time: 53 seconds)

e nao esta incluindo na minha tabela

Evandro

1 Resposta

ramilani12

Adicionou o driver no seu CLASSPATH ?

Criado 9 de novembro de 2006
Ultima resposta 9 de nov. de 2006
Respostas 1
Participantes 2