无法从底层数据库获取连接! - HSQL DB
我想通过Gavin King的Java Persistence与Hibernate学习Hibernate。无法从底层数据库获取连接! - HSQL DB
我刚刚下载从这个位置http://downloads.jboss.org/hibernate/caveatemptor/jpwh-gettingstarted-070401.zip
书中给出的例子,我开始我的HSQL DB使用蚂蚁startdb和数据库成功启动。
当试图运行目标的SchemaExport我收到以下错误..
SchemaExport工具:[hibernatetool] 执行的Hibernate工具与 标准配置[hibernatetool] 1.任务:就是hbm2ddl(生成数据库模式)[hibernatetool] 18:07:56,555 INFO Environment:500 - Hibernate 3.2.0.cr5 [hibernatetool] 18:07:56,555 INFO Environment:533 - hibernate.properties not fo und [hibernatetool] 18: 07:56,555信息 环境:667 - 字节码提供呃 名称:CG LIB [hibernatetool] 18:07:56571信息环境:584 - 使用JDK 1.4的java.sql.Time邮票 处理[hibernatetool] 18:07:56617 信息配置:1384 - 从文件中配置 :H ibernate.cfg.xml [hibernatetool] 18:07:56680 INFO 配置:507 - 读映射 从RES乌尔斯河:你好/ Message.hbm.xml [hibernatetool] 18:07:56758 INFO HbmBinder:300 - 映射类: hello.Message - > MESSAGES [hibernatetool] 18:07:56,851信息配置:1465 - 配置的SessionFactor y:null [hibernatetool] 18:07:56,851信息 方言:141 - 使用方言: org.hibernate.di alect.HSQLDialect [hibernatetool] 18:07:56914 INFO SchemaExport工具:154 - 运行就是hbm2ddl 架构EXP ORT [hibernatetool] 18:07:56914 INFO SchemaExport工具: 174 - 写入生成的模式到文件: C:\用户\拉梅什\桌面\教程\休眠\休眠 代码样本\ jpwh- gettingstarted-070401 \ HelloWorld的天然\的HelloWorld-ddl.sql [hibernatetool] 18: 07:56,914 INFO SchemaExport:179 - 导出生成 模式到数据库[hibernatetool] 18:07:56,914信息 C3P0ConnectionProvider:50 - C3P0使用 驱动程序:在org.hsqldb.jdbcDriver URL: JDBC:HSQLDB:HSQL://本地主机 [hibernatetool] 18:07:56914 INFO C3P0ConnectionProvider:51 - 连接 正确关系:{用户= SA} [hibernatetool] 18:07:56914 INFO C3P0ConnectionProvider:54 - 自动提交 模式:假[hibernatetool] 18:08:26554 WARN BasicResourcePool:1222 - com.mchange.v2.resou [email protected] - 收购尝试失败!清理未完成的采集。尽管 试图获取所需的新资源 资源,但我们仍然获得了比最大允许获取次数 (30)更多的 。 [hibernatetool] 18:08:26554 ERROR SchemaExport工具:202 - 架构出口 不成功
[hibernatetool]值java.sql.SQLException: 连接无法从 前作基础数据库获取! [hibernatetool]在 com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.j AVA:104)[hibernatetool]在 com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.che ckoutPooledConnection(C3P0PooledConnectionPool.java :236) [hibernatetool]在 com.mchange.v2.c3p0.PoolBackedDataSource.getConnectio N(PoolBackedDataSource.java:94) 在[hibernatetool] org.hibernate.connection.C3P0ConnectionProvider.getCo nnection(C3P0ConnectionProvider.java :35) [hibernatetool] at org.hibernate.tool.hbm2ddl.ManagedProviderConnectionH elper.prepare(ManagedProviderConnectio nHelper.java:28) [hibernatetool]在 org.hibernate.tool.hbm2ddl.SchemaExport.execute(舍姆 aExport.java:180)[hibernatetool]
在 org.hibernate.tool.hbm2ddl.SchemaExport.create (模式 Export.java:133)[hibernatetool]
在 org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(血红蛋白 m2DDLExporterTask.java:55) 在 org.hibernate.tool.ant [hibernatetool]。 HibernateToolTask.execute(Hibe rnateToolTask.java:171) [hibernatetool] at org.apache.tools.ant.UnknownElement.execute(UnknownEl ement.java:291)[hibernatetool]
在 sun.reflect.NativeMethodAccessorImpl.invoke0(母语 中号ethod)[hibernatetool]在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMet hodAccessorImpl.java:39) [ hibernatetool]在 sun.reflect.DelegatingMethodAccessorImpl.invoke(德勒 atingMethodAccessorImpl.java:25) [hibernatetool]在 java.lang.reflect.Method.invoke(Method.java:597) [hibernatetool]在 有机apache.tools.ant.dispatch.DispatchUtils.execute(D ispatchUtils.java:106)[hibernatetool] at org.apache.tools.ant.Task.perform(Task.java:348) [hibernatetool]在 org.apache.tools.ant.Target.execute(Target.java:390) [hibernatetool]在 有机.apache.tools.ant.Target.performTasks(Target.java: 411)[hibernatetool]在 org.apache.tools.ant.Project.executeSortedTargets(临 ject.java:1397)[hibernatetool]
在 org.apache.tools.ant.Project.executeTarget(Project.ja VA:1366)[hibernatetool]在 org.apache.tools.ant.helper.DefaultExecutor.executeTa rgets(DefaultExecutor.java:41) [hibernatetool ]在 org.apac he.tools.ant.Project.executeTargets(Project.j AVA:1249)[hibernatetool]在 org.apache.tools.ant.Main.runBuild(Main.java:801) [hibernatetool]在 org.apache .tools.ant.Main.startAnt(Main.java:218) [hibernatetool] at org.apache.tools.ant.launch.Launcher.run(Launcher。JAV 一个:280)[hibernatetool]在 org.apache.tools.ant.launch.Launcher.main(Launcher.ja VA:109)[hibernatetool]所致: com.mchange.v2.resourcepool.CannotAcquireResourceExce ption:一个ResourcePool不能从 工厂或工厂获取资源 。 [hibernatetool]
在 com.mchange.v2.resourcepool.BasicResourcePool.awaitAc 叠纸(BasicResourcePool.java:970) [hibernatetool]在 com.mchange.v2.resourcepool.BasicResourcePool.checkou tResource(BasicResourcePool.java :208) [hibernatetool]在 com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.che ckoutPooledConnection(C3P0PooledConnectionPool.java:232) [hibernatetool] ...同时执行时发生24更 [hibernatetool] 1个错误 。 [hibernatetool]错误#1: java.sql.SQLException:连接 无法从 底层数据库中获得! [hibernatetool] 18:08:26569 WARN BasicResourcePool:1222 - com.mchange.v2.resou [email protected] - 采集尝试失败!!!清理未完成的采集。虽然 试图获取所需的新 的资源,我们的固定资产投资导致成功超过允许 获取尝试(30)的最大数量.`
更 我没有关于任何hiberate或太多的知识HSQL ..
有人请说明这里有什么错?
感谢
编辑:我试图运行项目helloworld-native
。
在startdb蚂蚁的build.xml给出的目标是如下:
<!-- Start the HSQL DB server -->
<target name="startdb" description="Run HSQL database server with clean DB">
<!-- Delete database files -->
<delete dir="${database.dir}"/>
<java classname="org.hsqldb.Server"
fork="yes"
classpathref="project.classpath"
failonerror="true">
<arg value="-database.0"/>
<arg value="file:${database.dir}/db"/>
</java>
</target>
,当我运行命令ant startdb
我看到下面的输出:
startdb:
[delete] Deleting directory C:\Users\Ramesh\Desktop\Tutorials\hibernate\Hibernate Code samples\jpwh-gettingstarted-070401\helloworld-native\database
[java] [[email protected]]: [Thread[main,5,main]]: checkRunning(false) entered
[java] [[email protected]]: [Thread[main,5,main]]: checkRunning(false) exited
[java] [[email protected]]: Startup sequence initiated from main() method
[java] [[email protected]]: Loaded properties from [C:\Users\Ramesh\Desktop\Tutorials hibernate\Hibernate Code samples\jpwh-gettingstarted-070401\helloworld-native\server.properties]
[java] [[email protected]]: Initiating startup sequence...
[java] [[email protected]]: Server socket opened successfully in 29 ms.
[java] [[email protected]]: Database [index=0, id=0, db=file:database/db, alias=] opened sucessfully in 469 ms.
[java] [[email protected]]: Startup sequence completed in 523 ms.
[java] [[email protected]]: 2010-11-08 22:11:08.027 HSQLDB server 1.8.0 is online
[java] [[email protected]]: To close normally, connect and execute SHUTDOWN SQL
[java] [[email protected]]: From command line, use [Ctrl]+[C] to abort abruptly
然后,我想我只在服务器模式下运行HSQL DB(从上面的输出)..
请告诉我还有什么我丢失..
更新:经过第二次查看,看起来我错了,您可以使用ant脚本在服务器模式下启动HSQL,并且您不必使用命令行。其实,我试图重现与helloworld-native
样品的问题,但它对我来说工作得很好。
首先,我在第一外壳采用ant startdb
开始HSQLDB:
$ ant startdb
Buildfile: /home/pascal/Projects/jpwh-gettingstarted-070401/helloworld-native/build.xml
startdb:
[java] [[email protected]]: [Thread[main,5,main]]: checkRunning(false) entered
[java] [[email protected]]: [Thread[main,5,main]]: checkRunning(false) exited
[java] [[email protected]]: Startup sequence initiated from main() method
[java] [[email protected]]: Loaded properties from [/home/pascal/Projects/jpwh-gettingstarted-070401/helloworld-native/server.properties]
[java] [[email protected]]: Initiating startup sequence...
[java] [[email protected]]: Server socket opened successfully in 39 ms.
[java] [[email protected]]: Database [index=0, id=0, db=file:database/db, alias=] opened sucessfully in 1148 ms.
[java] [[email protected]]: Startup sequence completed in 1281 ms.
[java] [[email protected]]: 2010-11-08 18:29:20.094 HSQLDB server 1.8.0 is online
[java] [[email protected]]: To close normally, connect and execute SHUTDOWN SQL
[java] [[email protected]]: 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
。
尝试与MySQL..and它工作..不知道什么是probelm? – javanoob 2010-11-07 13:23:19