JDBC嵌入式Derby:找不到合适的驱动程序

时间:2017-07-14 20:41:31

标签: java jdbc netbeans derby embedded-database

我正在尝试使用嵌入式Derby编写程序,但是当我运行它时,它会显示:

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
...

代码:

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


}

}
}

3 个答案:

答案 0 :(得分:2)

gdtu之后的列应该用分号替换。

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

答案 1 :(得分:0)

这看起来像配置问题,

您是否设置了classpath变量?

如果您正在使用:

    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:

完成后,尝试打印路径以查看变量是否已正确配置:

Windows: echo %CLASSPATH% 
Unix: echo $CLASSPATH

然后执行java org.apache.derby.tools.sysinfo以查看服务器的信息

[编辑]:抱歉,我想念添加德比工具

答案 2 :(得分:0)

检查derbyclient.jar是否在类路径上,并且在服务器模式下工作时是否正在加载相应的驱动程序org.apache.derby.jdbc.ClientDriver