简体   繁体   English

通过JDBC连接到Derby数据库失败

[英]Connecting to a Derby Database through JDBC fails

I'm trying to build a simple spring app which needs to have the ability to communicate with a database. 我正在尝试构建一个简单的Spring应用程序,该应用程序必须具有与数据库进行通信的能力。 Following a tutorial I have completed the entire code of my app however when I run my app I get this: 在学习完教程之后,我已经完成了应用程序的全部代码,但是当我运行应用程序时,我得到了以下信息:

    Exception in thread "main" java.lang.IllegalStateException: Could not load JDBC driver class [org.apache.derby.jdbc.EmbeddedDruver]
    at org.springframework.jdbc.datasource.DriverManagerDataSource.setDriverClassName(DriverManagerDataSource.java:130)
    at main.Application.main(Application.java:15)
Caused by: java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDruver
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at org.springframework.jdbc.datasource.DriverManagerDataSource.setDriverClassName(DriverManagerDataSource.java:127)
    ... 1 more

Here is the code which sets the data source and the jdbc: 这是设置数据源和jdbc的代码:

        DriverManagerDataSource ds = new DriverManagerDataSource();
        ds.setDriverClassName("org.apache.derby.jdbc.EmbeddedDruver");
        ds.setUrl("jdbc:derby:c:\\temp\\database\\test01;create=true");
        ds.setUsername("");
        ds.setPassword("");
        siod.setDataSource(ds);

I used SQuirrel to create my db. 我使用SQuirrel创建了数据库。 I'm 100% certain that is the path. 我100%确信这就是路。 Here is an image which tells what path the db has: http://postimg.org/image/4tbfsxql9/ 这是一张告诉数据库的路径的图像: http : //postimg.org/image/4tbfsxql9/

I'm sure there a simple answer to my question. 我敢肯定我的问题有一个简单的答案。 Thank you. 谢谢。

The correct spelling is "org.apache.derby.jdbc.EmbeddedDriver" not EmbeddedDruver. 正确的拼写是“ org.apache.derby.jdbc.EmbeddedDriver”而不是EmbeddedDruver。

If that doesn't fix it, check that you have your classpath set to include the Derby jar(s). 如果那不能解决问题,请检查是否已将类路径设置为包括Derby jar。 This can either be as explained here or by including the Derby jar(s) with other jars in the library of your application. 可以按照此处的说明进行操作,也可以将Derby jar与其他jar一起包含在应用程序库中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM