嵌入式H2数据库:正在建立连接,但未找到表 [英] Embedded h2 database: getting connection but table not found

查看:440
本文介绍了嵌入式H2数据库:正在建立连接,但未找到表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用h2嵌入式数据库.当我启动我的应用程序时,数据库被初始化,并且我能够获得连接对象.但是,当应用程序尝试在表中插入数据时,它将引发sql异常未找到表XXXX".

I am using h2 embedded db. When I start my application the db gets initialized and I am able to get connection object. However when application tries to insert data in the table it throws the sql exception 'table XXXX not found'.

我能够从H2控制台查看表格.同样的查询可以在控制台上完美运行.

I am able to view the tables from H2 consoles. And same query runs perfectly on the console.

通过本主题另一个问题的答案,我已经了解到当数据库为空时会发生这种情况.但是从H2控制台,我可以查看和执行查询,并且可以交叉检查它是否是同一数据库,因为我使用的网址和用户完全相同,因此可以通过应用程序和H2控制台进行连接.

Going through some of the answers of the other question on this topic, I've understood such behavior occurs when the database is empty. But from the H2 console I am able to view and execute queries and I have cross check it is the same db because I am using the exact same url and user to connect both through application and through H2 console.

有什么建议可以解决吗?

Any suggestions to resolve?

推荐答案

所有特权均已到位.所以有一件事可以肯定,我确实指向了错误的数据库.但是我怎么不知道.然后我注意到,当我第一次启动应用程序服务器时,创建的db文件的扩展名为mv.db.当我第一次通过h2控制台连接时,创建了扩展名为h2.db的文件. 因此,确实为同一用户和url创建了两个不同的数据库.

All privileges were in place. So one thing was for sure that I was indeed pointing to the wrong db. But how I did not know. Then I noticed that when I started the application server for the first time, the db file that got created was of extension mv.db. When I connected through h2 console for the first time, a file with extension h2.db got created. So indeed two different databases were getting created for the same user and url.

原因是我的应用程序中存在的h2驱动程序jar版本为1.4(测试版),该版本创建了扩展名为mv.db的db.我正在访问的控制台是通过创建h2.db文件的h2版本1.3(最后一个稳定版本)进行的.

The reason was that the h2 driver jar that was present in my application was of version 1.4 (beta) which creates db with extension mv.db. The console that I was accessing was through h2 version 1.3 (last stable) which creates h2.db file.

此问题的出现是由于应用程序和控制台之间的版本不匹配.当我将两者都移至1.4(测试版)后,问题就解决了.

This issue was coming due to version mismatch between application and console. Once I moved both to 1.4 (beta) the issue was resolved.

这篇关于嵌入式H2数据库:正在建立连接,但未找到表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆