Problemas com conexão

1 resposta
H

ESSA CONEXÃO NÃO ESTÁ DANDO CERTO

Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);

String JspHome = getServletContext().getRealPath("/");

String LocalBD=JspHome.concat("/banco/clientes.mdb");

Connection ligacao = DriverManager.getConnection(

“jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=” + LocalBD);

Statement comando=ligacao.createStatement();

APARECE O SEGUINTE ERRO:

[Microsoft][Driver ODBC para Microsoft Access] ‘(desconhecido)’ não é um caminho válido. Certifique-se de que o nome do caminho esteja escrito corretamente e que você esteja conectado ao servidor no qual o arquivo reside.

JÁ VERIFIQUEI TUDO,O CAMINHO E AS PASTAS.

1 Resposta

P

Dah um olhada nesse código fonte pra ver se te ajuda de alguma forma... []'s

/*
 * Conexao.java
 *
 * Created on 15 de Julho de 2003, 15:07
 */

import java.lang.*;
import java.sql.*;

public class Conexao{

  private Connection conex;
  private Statement state;  


/*Construtor*/
  public Conexao(){           
  /*Drive*/    
    try{
  //instanciando um drive
      Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    }catch(ClassNotFoundException excessao){      
      System.err.print("ClassNotFoundException - the class wasn't found.");      
    }catch(IllegalAccessException excessao){
      System.err.print("IllegalAccessException - the class or initializer is not accessible. ");
    }catch(InstantiationException excessao){
      System.err.print("InstantiationException - this Class represents an abstract class, an interface, an array class, a primitive type, or void; or the instantiation fails for some other reason.");
    }catch(ExceptionInInitializerError excessao){
      System.err.print("ExceptionInInitializerError - the initialization provoked by this method fails.");
    }catch(SecurityException excessao){
      System.err.print("SecurityException - there is no permission to create a new instance.");
    }
    
  /*Conexao com o banco*/    
    try{ 
      conex = DriverManager.getConnection("jdbc:mysql://localhost/modulo1","administrador","administrador");
    }catch(SQLException excessao){
      System.err.print("SQLException - a database access error occurs.");
    }
    
  /*Interface com o Banco*/    
    try{
      state = conex.createStatement();
    }catch(SQLException excessao){
      System.err.print("SQLException - a database access error occurs.");
    }
    
  }
  

/*Metodos para Pesquisa*/
  public ResultSet execQuery (String sql) throws SQLException {
    return state.executeQuery(sql);
/*Executes an SQL statement that returns a single ResultSet object*/    
  }
  
  public int execUpdate (String sql) throws SQLException {
    return state.executeUpdate(sql);
/*Executes an SQL INSERT, UPDATE or DELETE statement*/    
  }
  
/*Destrutor - executado quando a memória alocada para o objeto estiver para ser liberada*/
  protected void finalize (){
    try{
      conex.close();
    }catch(SQLException excessao){
      System.err.print("SQLException - a database access error occurs.");
    }
  }
  
}
Criado 23 de dezembro de 2004
Ultima resposta 23 de dez. de 2004
Respostas 1
Participantes 2