Problems with connection to the MS Acces bank

Asked

Viewed 365 times

4

Staff I developed a web application whose database is MS Access, well, when the user logs in I send the data by ajax to the java class to do the login and password validation, the problem is that when the system will connect in the database my connection class gives the following error "java.sql.Sqlexception: No suitable driver found for jdbc:ucanaccess://banco_data softTech.accdb" Until then ok is not finding a driver, but I decided to do a test and created a method "public Static void main" in my connection class, and called the same login validation method, the class was as follows:

public static Connection conectar() {
    Connection conexao = null;
    try {
        conexao = DriverManager.getConnection("jdbc:ucanaccess://banco_dados\\softTech.accdb");
    } catch (Exception e) {
        System.out.println("Erro na conexão com o banco " + e.toString());
    }
    return conexao;
}

public static void main(String[] args) {
    try {
        Funcionario f = new Funcionario();
        f.setLoginFuncionario("TESTE");
        f.setSenhaFuncionario("TESTE");
        String resultado = new FuncionarioDAO().validaLogin(f);
        System.out.println(resultado);
    } catch (Exception e) {
        System.out.println(e.toString());

    }
}

When running this class it is that the thing gets strange, because the connection is done normally, I do not know what might be going on need help

The mistake is this:

java.sql.Sqlexception: No suitable driver found for jdbc:ucanaccess://src/banco_data/softTech.accdb

but as I said the driver was entered yes, and when I test direct by the class it gives no error at all.

1 answer

0

Try to add Class.forName() :

  public static Connection conectar(){
     Connection conexao = null;
         try  {
            Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
    conexao  = DriverManager.getConnection("jdbc:ucanaccess://banco_dados\\softTech.accdb");
             }
             catch (Exception e) {
        System.out.println("Erro na conexão com o banco " + e.toString());
    }
    return conexao;
}

The problem here is that older versions of Java used to connect ODBC with MS-Access and the ODBC driver was removed in current versions of Java.

  • Hello Falion, taking a closer look at the error message I realized the following excerpt " net.ucanaccess.jdbc.Ucanaccesssqlexception: Given file does not exist: banco_dados softTech.accdb" or by the way my application is not finding my access file, this means either I’m putting the file in the wrong place within the project (if that’s where it would be ideal to put ?), or else I’m writing the path wrong (if that’s how it should be then ?), thanks in advance !

  • Hello friend, try to write the whole way to the . accdb, example : 'jdbc:ucanaccess://c://Folder/softTech.accdb' this can correct your error, because usually Java consists of giving errors of this type because there is no correct path to the location.

  • If I helped you, :)

  • For example, did you use the DSN for the connection? whenever there is MS in the move has to use more than one path to the file create an alias for the file and export together in the duplicate/installation. always solves ....

Browser other questions tagged

You are not signed in. Login or sign up in order to post.