Aliyu Heidar Umar
Aliyu Heidar Umar

Reputation: 53

JDBC embedded Derby: No suitable driver found

I'm trying to write a program with embedded Derby, but when I run it, it displays:

run:
Jul 14, 2017 9:19:54 PM gfdh.Login Doconnect
SEVERE: null
java.sql.SQLException: No suitable driver found for jdbc:derby:gdtu:create=true
...

Code:

public class Login extends javax.swing.JFrame {

Connection con;
Statement stmt;
ResultSet rs;

private static final String DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
private static final String JDBC_URL = "jdbc:derby:gdtu:create=true";

public Login(){
    initComponents();
    Doconnect();
}

private void Doconnect(){

    try {
        this.con = DriverManager.getConnection(JDBC_URL);
        if(this.con != null){
            System.out.println("Connected to database");
        }
    } catch (SQLException ex) {
        Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
    }


}

}
}

Upvotes: 0

Views: 850

Answers (3)

Aliyu Heidar Umar
Aliyu Heidar Umar

Reputation: 53

the column after gdtu should be replaced with semicolon.

private static final String JDBC_URL = "jdbc:derby:gdtu;create=true";

Upvotes: 2

Ivan Lynch
Ivan Lynch

Reputation: 562

This looks like to a configuration problem,

Did you set your classpath variable?

If you are using:

    Windows - set CLASSPATH=%DERBY_INSTALL%\lib\derby.jar;%DERBY_INSTALL%\lib\derbytools.jar;
    Unix - export CLASSPATH=$DERBY_INSTALL/lib/derby.jar:$DERBY_INSTALL/lib/derbytools.jar:

Once you have done try printing the path to see if the variable are correctly configured:

Windows: echo %CLASSPATH% 
Unix: echo $CLASSPATH

then execute java org.apache.derby.tools.sysinfo to see the info of your server

[EDIT]: Sorry i miss to add the derby tools

Upvotes: 0

Jeremy
Jeremy

Reputation: 336

Check that derbyclient.jar is on the class path and that you are loading the appropriate driver org.apache.derby.jdbc.ClientDriver when working in server mode.

Upvotes: 0

Related Questions