ERRO de Inclusão

Estou tentando fazer uma rotina de inclusão…Tenho uma interface gráfica para isso…quando executo e clico no botão inserir aparece o seguinte erro:
Já configurei o classpath setei para os tres arquivos .jar.

java.lang.ClassNotFoundException:
com.microsoft.jdbc.sqlserver.SQLServerDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at Conexao.Conecta.getConnection(Conecta.java:77)
at janCategoria.cmdInserirActionPerformed(janCategoria.java:136)
at janCategoria.access$100(janCategoria.java:11)
at janCategoria$2.actionPerformed(janCategoria.java:83)
at
javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
at
javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)

    at

javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)

    at

javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)

    at java.awt.Component.processMouseEvent(Component.java:5100)
    at java.awt.Component.processEvent(Component.java:4897)
    at java.awt.Container.processEvent(Container.java:1569)
    at java.awt.Component.dispatchEventImpl(Component.java:3615)
    at java.awt.Container.dispatchEventImpl(Container.java:1627)
    at java.awt.Component.dispatchEvent(Component.java:3477)
    at

java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
at
java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

-----------código-----------------
CLASSE: CONEXAO

package Conexao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Conecta {
private Connection con = null;
private String hostName = null;
private String userName = null;
private String password = null;
private String url = null;
private String jdbcDriver = null;
private String dataBaseName = null;
private String dataBasePrefix = null;
private String dabaBasePort = null;

public Conecta() {
super();

hostName = "suport03";
userName = "user";
password = "123456";    
jdbcDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
dataBaseName = "Midia";
dataBasePrefix = "jdbc:microsoft:sqlserver://";
dabaBasePort = "1433";

url = dataBasePrefix + hostName + ":"+dabaBasePort+"/" + dataBaseName;

}
/**

  • Retorna uma java.sql.Connection.
  • @return con
    /
    public Connection getConnection() {
    try {
    if (con == null) {
    Class.forName(jdbcDriver);
    con = DriverManager.getConnection(url, userName, password);
    } else if (con.isClosed()) {
    con = null;
    return getConnection();
    }
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    return con;
    }
    /
    *
  • Fecha a conexão com BD.

*/
public void closeConnection() {
if (con != null) {
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}

CLASSE: janCategoria

public class janCategoria extends javax.swing.JFrame {

public janCategoria() {
    initComponents();
}

    private void initComponents() {
    java.awt.GridBagConstraints gridBagConstraints;
    lblNome = new javax.swing.JLabel();
    txtNome = new javax.swing.JTextField();
    tblDescricao = new javax.swing.JTable();
    cmdInserir = new javax.swing.JButton();
    cmdAlterar = new javax.swing.JButton();
    cmdExcluir = new javax.swing.JButton();
    cmdSair = new javax.swing.JButton();
    getContentPane().setLayout(new java.awt.GridBagLayout());
    setTitle("Cadastro de Categoria");
    setName("fraCategoria");
    addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent evt) {
            exitForm(evt);
        }
    });
    lblNome.setText("Nome:");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.ipadx = 4;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    getContentPane().add(lblNome, gridBagConstraints);
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridwidth = 8;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.ipadx = 254;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    getContentPane().add(txtNome, gridBagConstraints);
    tblDescricao.setFont(new java.awt.Font("Tahoma", 0, 10));
    tblDescricao.setModel(new javax.swing.table.DefaultTableModel(
        new Object [][] {
            {null, null, null, null},
            {null, null, null, null},
            {null, null, null, null},
            {null, null, null, null}
        },
        new String [] {
            "Title 1", "Title 2", "Title 3", "Title 4"
        }
    ));
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 3;
    gridBagConstraints.gridwidth = 10;
    gridBagConstraints.ipadx = 240;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    getContentPane().add(tblDescricao, gridBagConstraints);
    cmdInserir.setText("Inserir");
    cmdInserir.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            cmdInserirActionPerformed(evt);
        }
    });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 5;
    gridBagConstraints.gridwidth = 3;
    gridBagConstraints.ipadx = 5;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    getContentPane().add(cmdInserir, gridBagConstraints);
    cmdAlterar.setText("Alterar");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 4;
    gridBagConstraints.gridy = 5;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    getContentPane().add(cmdAlterar, gridBagConstraints);
    cmdExcluir.setText("Excluir");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 6;
    gridBagConstraints.gridy = 5;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    getContentPane().add(cmdExcluir, gridBagConstraints);
    cmdSair.setText("Sair");
    cmdSair.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            cmdSairActionPerformed(evt);
        }
    });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 8;
    gridBagConstraints.gridy = 5;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    getContentPane().add(cmdSair, gridBagConstraints);
    pack();
}
private void cmdInserirActionPerformed(java.awt.event.ActionEvent evt) {
    Conecta conecta = new Conecta();
    Statement stmt = null;
    
    String descricao = txtNome.getText();
    String codigo = "1";
    String inserir = "insert into Categoria(codigo,descricao) values (codigo, descricao)";
            
    try{
        stmt = conecta.getConnection().createStatement();
        stmt.executeUpdate(inserir);
        stmt.close();
        conecta.closeConnection();
    } catch (SQLException e) {
        e.printStackTrace();
        System.out.println("Erro ao executar o Insert ou ao fechar a conexão");
    }
}
private void cmdSairActionPerformed(java.awt.event.ActionEvent evt) {
            System.exit(0);
}
    private void exitForm(java.awt.event.WindowEvent evt) {
    System.exit(0);
}

    public static void main(String args[]) {
    new janCategoria().show();
}

private javax.swing.JButton cmdAlterar;
private javax.swing.JButton cmdExcluir;
private javax.swing.JButton cmdInserir;
private javax.swing.JButton cmdSair;
private javax.swing.JLabel lblNome;
private javax.swing.JTable tblDescricao;
private javax.swing.JTextField txtNome;

}

jdbcDriver = "com.Micro$oft.jdbc.sqlserver.SQLServerDriver"; (...) dataBasePrefix = "jdbc:Micro$oft:sqlserver://";

Tem certeza que tem esse $ em Micro$oft ?

É que o código PHP deste fórum, ou sua customização, tem alguma coisa que substitui “microsoft” por “micro$oft”… Tem de escrever “microsoft” para ele não ficar mudando…

Depois que a Sun recebeu US$ 1,6 Bilhões de dólares da Microsoft para entrarem em acordo judicial sobre o Java, só falta o fórum trocar Sun por $un…

http://www.microsoft.com/presspass/press/2004/apr04/04-02SunAgreementPR.asp

O que interessa no link acima:

The agreements involve payments of $700 million to Sun by Microsoft to resolve pending antitrust issues and $900 million to resolve patent issues. In addition, Sun and Microsoft have agreed to pay royalties for use of each other’s technology, with Microsoft making an up-front payment of $350 million and Sun making payments when this technology is incorporated into its server products.

Voltando ao assunto original.
Tenha certeza que vc colocou o jar como driver jdbc da MS no classpath.

Abracos

Tenho sim está assim:
Nome da variável: classpath
Valor da variável: c:javalibsmsbase.jar;c:javalibsmsutil.jar;c:javalibsmssqlserver.jar;

estou usando o netBeans! tentei fazer a conexão pelo runtime -> Databases. Selecionei o driver “mssqlserver.jar” e ele completou os campos tudo certinho…fui na databases e pedi para fazer uma conexão…veio tudo com uma receita de bolo…só alterei as informações e pedi para conectar e veio essa mensagem

Annotation: Exception occurred in Request Processor
java.lang.NoClassDefFoundError: com/microsoft/jdbc/base/BaseDriver
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:219)
at org.netbeans.modules.db.explorer.DatabaseConnection$1.run(DatabaseConnection.java:338)
at org.openide.util.Task.run(Task.java:136)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:330)
[catch] at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:686)

tente CLASSPATH (maiúsculas).

Já tentei assim e não deu certo

colocou Microsoft com M maiúscula? ponha como ‘m’.

Está com minusculo.

Quando configurei o netbeans para o driver ele colocou a com.microsoft…tudo com letra minuscula!

que tal executar de fora do NetBeans?

:o)… já tentei tb…mas era pra dar certo de qualquer um dos dois jeitos… certo?

Vc jah tentou averiguar onde seu classLoader está indo buscar os jars???

Tenta colocar isto no seu metodo main:

System.out.println(NomeClasseDoMetodoMain.class.getResource("."))

Este seria o diretorio base do seu classLoader… O jar do seu driver deve estar ai ou em algum subdiretorio daih…

Caso esteja em um subdiretorio, garanta q ele está explicito no classpath:

-cp ./subDir/MS????.jar

O erro dimuniu…mas continua…o Class=Loader tá apontando para aqui “file:/C:/Documents%20and%20Settings/felipe/.netbeans/3.6/system/” coloquei os tres arquivos jar nesta pasta e deu essa mensagem de erro…e no final imprimiu o classloader…

java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at Conexao.Conecta.getConnection(Conecta.java:77)
at janCategoria.cmdInserirActionPerformed(janCategoria.java:136)
at janCategoria.access$100(janCategoria.java:11)
at janCategoria$2.actionPerformed(janCategoria.java:83)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
at java.awt.Component.processMouseEvent(Component.java:5100)
at java.awt.Component.processEvent(Component.java:4897)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
at java.awt.Container.dispatchEventImpl(Container.java:1613)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
java.lang.NullPointerException
at janCategoria.cmdInserirActionPerformed(janCategoria.java:136)
at janCategoria.access$100(janCategoria.java:11)
at janCategoria$2.actionPerformed(janCategoria.java:83)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
at java.awt.Component.processMouseEvent(Component.java:5100)
at java.awt.Component.processEvent(Component.java:4897)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
at java.awt.Container.dispatchEventImpl(Container.java:1613)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
file:/C:/Documents%20and%20Settings/felipe/.netbeans/3.6/system/

Olha soh…

C vc colocou os arquivos diretamente onde o classloader procura e ele esta dizendo q nao esta achando, eh pq realmente esta faltando um arquivo…

Para testar o arquivo q vc acha q esta certo faz o seguinte.

jar -tf nomeDoJar.jar 1>teste.txt

Depois, dah uma olhada neste arquivo “teste.txt”.

C ele nao contiver "com.Micro$oft.jdbc.sqlserver.SQLServerDriver " eh pq esta errado.

Outra alternativa eh abrir o jar utilizando o Winzip mesmo e procurar a classe “SQLServerDriver” em seu conteudo !

Ele contém a classe!

se mata então!