无法从底层数据库获取连接! - HSQLDB

时间:2010-11-07 12:48:09

标签: java hibernate orm hsqldb

1 个答案:

答案 0 :(得分:1)

更新:经过第二次查看,看来我错了,您可以使用ant脚本在服务器模式下启动HSQL,而您不必使用命令行。实际上,我尝试使用helloworld-native样本重现问题,但它对我来说很好。

首先,我使用ant startdb

在第一个shell中启动了HSQLDB
$ ant startdb 
Buildfile: /home/pascal/Projects/jpwh-gettingstarted-070401/helloworld-native/build.xml

startdb:
     [java] [Server@a97b0b]: [Thread[main,5,main]]: checkRunning(false) entered
     [java] [Server@a97b0b]: [Thread[main,5,main]]: checkRunning(false) exited
     [java] [Server@a97b0b]: Startup sequence initiated from main() method
     [java] [Server@a97b0b]: Loaded properties from [/home/pascal/Projects/jpwh-gettingstarted-070401/helloworld-native/server.properties]
     [java] [Server@a97b0b]: Initiating startup sequence...
     [java] [Server@a97b0b]: Server socket opened successfully in 39 ms.
     [java] [Server@a97b0b]: Database [index=0, id=0, db=file:database/db, alias=] opened sucessfully in 1148 ms.
     [java] [Server@a97b0b]: Startup sequence completed in 1281 ms.
     [java] [Server@a97b0b]: 2010-11-08 18:29:20.094 HSQLDB server 1.8.0 is online
     [java] [Server@a97b0b]: To close normally, connect and execute SHUTDOWN SQL
     [java] [Server@a97b0b]: From command line, use [Ctrl]+[C] to abort abruptly

然后,我从另一个shell运行ant schemaexport

$ ant schemaexport 
Buildfile: /home/pascal/Projects/jpwh-gettingstarted-070401/helloworld-native/build.xml

compile:
    [mkdir] Created dir: /home/pascal/Projects/jpwh-gettingstarted-070401/helloworld-native/build
    [javac] /home/pascal/Projects/jpwh-gettingstarted-070401/helloworld-native/build.xml:39: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 3 source files to /home/pascal/Projects/jpwh-gettingstarted-070401/helloworld-native/build

copymetafiles:
     [copy] Copying 3 files to /home/pascal/Projects/jpwh-gettingstarted-070401/helloworld-native/build

schemaexport:
[hibernatetool] Executing Hibernate Tool with a Standard Configuration
[hibernatetool] 1. task: hbm2ddl (Generates database schema)
[hibernatetool] 
[hibernatetool]     alter table MESSAGES 
[hibernatetool]         drop constraint FK_NEXT_MESSAGE;
[hibernatetool] 
[hibernatetool]     drop table MESSAGES if exists;
[hibernatetool] 
[hibernatetool]     create table MESSAGES (
[hibernatetool]         MESSAGE_ID bigint generated by default as identity (start with 1),
[hibernatetool]         MESSAGE_TEXT varchar(255),
[hibernatetool]         NEXT_MESSAGE_ID bigint,
[hibernatetool]         primary key (MESSAGE_ID)
[hibernatetool]     );
[hibernatetool] 
[hibernatetool]     alter table MESSAGES 
[hibernatetool]         add constraint FK_NEXT_MESSAGE 
[hibernatetool]         foreign key (NEXT_MESSAGE_ID) 
[hibernatetool]         references MESSAGES;
[hibernatetool] 1 errors occurred while performing <hbm2ddl>.
[hibernatetool] Error #1: java.sql.SQLException: Table not found: MESSAGES in statement [alter table MESSAGES]

BUILD SUCCESSFUL
Total time: 14 seconds

事实上,在运行ant dbmanager时,我可以按预期看到MESSAGES表。

所以一切正常,开箱即用。如果它不适合您,可能会开始查看网络问题,个人防火墙等内容。


根据跟踪,看起来HSQL没有启动(至少不是在服务器模式下),我怀疑你没有像你应该的那样启动它。要在服务器模式下启动它,请从helloworld-reverse目录运行(如启动HSQL数据库系统,第98页中所述):

$ java -cp lib/hsqldb.jar org.hsqldb.Server

然后,您将能够使用jdbc:hsqldb:hsql://localhost连接字符串连接到它。

相关问题