Error No suitable driver found when connecting with javaDB

1

I created a database using the javadb netbeans derby, then created a connection on port 1527 with the name of the Bank being TEST. I created the connection string below that I should connect to the TEST Bank, but with the code below I can not connect.

package javadata;

import java.sql.*;

/**
 *
 * @author Djafta
 */
public class JavaData {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        //PARAMETROS("jdbc:derby://host:port//DB;user=?;password=?");
        Connection conn = null;
        try {
            conn = DriverManager.getConnection("jdbc:derby://localhost:1527/TESTE","root","root");
            System.out.println("Conectado com sucesso...");

        } catch (SQLException ex) {
            System.out.println("Problema de conexao: " + ex);
        }


        //Statement sql = conn.createStatement();


    }

}

Now you're giving the error securing after adding the ex.printStackTrace ();:

java.sql.SQLException: No suitable driver found for jdbc:derby://localhost:1527/TESTE
    at java.sql.DriverManager.getConnection(DriverManager.java:689)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at javadata.JavaData.main(JavaData.java:25)
    
asked by anonymous 22.03.2018 / 20:47

1 answer

1

According to this post on SOEn , the problem can be two:

  • the driver may not be loading properly;
  • JDBC connection URL is poorly worded.

If the database has not yet been created, try adding create=true to the end of the connection url, so the database will create if it does not already exist. Without this parameter, if the database does not exist, java will throw an exception itself. In your case it would look like this:

"jdbc:derby://localhost:1527/TESTE;create=true"

By default, the bank is created where the bank service started, it would be interesting if you specify the location where the bank was created, then you can either replicate it or edit it with some other program. Giving an example of a database created in a folder called database on disk C: \:

"jdbc:derby://localhost:1527/C:/database/TESTE;create=true"

Also check that the derbyclient.jar jar has been added in the project classpath, since this jar is the javadb driver, necessary for java to be able to connect to this bank.

The driver can be found in this link , depending on your version of java.

PS: Although you have answers in the link indicated asking to register the driver, this action is no longer necessary since you are using jdk 6 or higher, since from this version of the API already comes with a version of JDBC that automatically registers the driver as added in the classpath.

    
27.03.2018 / 20:38