Problems with connection to MS Access bank

3

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 validation and password, the problem is that when the system will connect in the bank my connection class of the following error "java.sql.SQLException: No suitable driver found for jdbc: ucanaccess: // database_datas \ softTech.accdb" So, okay, I'm not finding a driver, but I decided to do a test and I created a "public static void main" method in my connection class, and I called the same login validation method, the class got 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 executing this class, the thing is strange, because the connection is done normally, I do not know what I might be needing help.

The error it gives is this:

  

java.sql.SQLException: No suitable driver found for jdbc: ucanaccess: //src/banco_dados/softTech.accdb

But as I said the driver was inserted yes, and when I test it directly through the class it does not give any errors.

    
asked by anonymous 31.05.2016 / 13:35

1 answer

0

Try adding 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 to ODBC with MS-Access and the ODBC driver was removed in the current versions of Java.

    
02.06.2016 / 21:05