无法在 Apache 7.0 上连接超音速(HSQLDB)数据库
Failed to connect hypersonic(HSQLDB) DB on Apache 7.0
我在 Eclipse 中有一个项目,在 Apache-Tomcat 7.0 服务器上被定义为 'Dynamic web project'。
我需要在我的一些 Java classses.
中连接到 hypersonic
DB (HSQLDB)
我要编写的代码非常简单:
private Connection getConnection(){
Connection conn;
try {
Class.forName("org.hsqldb.jdbcDriver");
conn = driverManager.getConnection("jdbc:hsqldb:hsql://localhost","sa","");
return conn;
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
我已经将 hsqldb.jar
添加到位于我的项目中并在 Eclipse 上的 Java build path
中定义的一些 lib
库。
问题是我遇到了这个错误:
java.lang.ClassNotFoundException: org.hsqldb.jdbcDriver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1722)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1573)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at root.login.getConnection(login.java:75)
at root.login.doPost(login.java:35)
所以由于某种原因它找不到 org.hsqldb.jdbcDriver
class。
不得不说,这个配置我之前做过很多次,都很顺利
Funny story:
I managed to have another simple Java project with main function and this function over the same configuration, and
it went well on the exact same machine.
- 我该怎么做才能找到这个 class?
- 我需要告诉您更多信息以使其更清楚吗?
在 Web 应用程序中,您必须将 hsqldb.jar
文件添加到应用程序的 WEB-INF/lib
文件夹中(或者添加到 $TOMCAT_HOME/lib
文件夹中,如果您有更多的 Web 应用程序在使用它)。仅将它放在 Eclipse 项目的类路径中是不够的。
我在 Eclipse 中有一个项目,在 Apache-Tomcat 7.0 服务器上被定义为 'Dynamic web project'。
我需要在我的一些 Java classses.
hypersonic
DB (HSQLDB)
我要编写的代码非常简单:
private Connection getConnection(){
Connection conn;
try {
Class.forName("org.hsqldb.jdbcDriver");
conn = driverManager.getConnection("jdbc:hsqldb:hsql://localhost","sa","");
return conn;
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
我已经将 hsqldb.jar
添加到位于我的项目中并在 Eclipse 上的 Java build path
中定义的一些 lib
库。
问题是我遇到了这个错误:
java.lang.ClassNotFoundException: org.hsqldb.jdbcDriver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1722)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1573)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at root.login.getConnection(login.java:75)
at root.login.doPost(login.java:35)
所以由于某种原因它找不到 org.hsqldb.jdbcDriver
class。
不得不说,这个配置我之前做过很多次,都很顺利
Funny story:
I managed to have another simple Java project with main function and this function over the same configuration, and it went well on the exact same machine.
- 我该怎么做才能找到这个 class?
- 我需要告诉您更多信息以使其更清楚吗?
在 Web 应用程序中,您必须将 hsqldb.jar
文件添加到应用程序的 WEB-INF/lib
文件夹中(或者添加到 $TOMCAT_HOME/lib
文件夹中,如果您有更多的 Web 应用程序在使用它)。仅将它放在 Eclipse 项目的类路径中是不够的。