Error No suitable driver found while connecting with javaDB

Asked

Viewed 517 times

1

I created a database using the javadb netbeans derby, then created a connection on port 1527 with the name of the Database being TEST. After that, I created the connection string below that should connect me to the TESTE Database, but with the code below I cannot 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 are giving the error asseguir after adding 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)
  • Does it give any error? If it does not give, try to put ex.printStackTrace(); in the catch to see if the exception is being captured.

  • Now giving the error: java.sql.Sqlexception: No suitable driver found for jdbc:derby://localhost:1527/TESTE

  • Dafta edits the question by adding the error stack of prinstacktrace, it seems that you can already know the cause.

  • It’s done. I realized it helps in organizing the page

  • You saw my answer below?

1 answer

1

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

  • the driver may not be being loaded properly;
  • the JDBC connection URL is misspelled.

If the database hasn’t been created yet, try adding create=true at the end of the connection url, the database will create if it does not exist. Without this parameter, if the database does not exist, java will trigger an exception. 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 was started, it would be interesting for you to specify the place of creation of the bank, to be able to then replicate or edit it with some other program. Giving an example of a database created in a folder called database on disc C:\:

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

Also check if the jar derbyclient.jar was added in the project classpath, because this jar is the javadb driver, necessary for java to be able to connect to this database.

The driver can be found at this link, according to your java version.


P.S.: despite having answers in the link indicated asking to register the driver, this action is no longer necessary since it is using jdk 6 or higher versions, as from this version the API already comes with a version of JDBC that automatically records the driver as added in the classpath.

Browser other questions tagged

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