0

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);
    }


}

}
}
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418

3 Answers3

2

the column after gdtu should be replaced with semicolon.

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

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

Ivan Lynch
  • 563
  • 5
  • 23
0

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.

Jeremy
  • 326
  • 4
  • 15