org.h2.jdbc.jdbcsqlexception:找不到表

发布于 2025-02-05 06:29:02 字数 1318 浏览 2 评论 0原文

我会得到这个例外:

org.h2.jdbc.JdbcSQLException:
Table "CUSTOMERS" not found; SQL statement:
SELECT * FROM CUSTOMERS

这是H2控制台。我在那里创建了一个表:

”

”在此处输入图像描述”

我有application.yml文件。我尝试添加db_close_delay = -1和database_to_upper = false:另外

spring:
  database:
    url: jdbc:h2:mem:testdb
  h2:
    console.enabled: true

,我有一个配置类,在其中创建了H2嵌入式数据库:

@Bean
public DataSource dataSource() {
    return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).build();
}

最后,查询。桌子被命名为客户:

public List<Customer> getAll() {
    return jdbcTemplate.query("SELECT * FROM CUSTOMERS", (resultSet, rowNum) -> {
        Customer customer = new Customer();
        customer.setId(resultSet.getLong("id"));
        customer.setName(resultSet.getString("name"));
        customer.setAge(resultSet.getInt("age"));
        return customer;
    });
}

我该怎么办?

I'm getting this exception:

org.h2.jdbc.JdbcSQLException:
Table "CUSTOMERS" not found; SQL statement:
SELECT * FROM CUSTOMERS

This is the H2 Console. I have created a table there:

H2 Console

enter image description here

I have the application.yml file. I have tried to add DB_CLOSE_DELAY=-1 and DATABASE_TO_UPPER=false as well:

spring:
  database:
    url: jdbc:h2:mem:testdb
  h2:
    console.enabled: true

Also, I have a configuration class, where I have created the H2 Embedded Database:

@Bean
public DataSource dataSource() {
    return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).build();
}

Finally, the query. The table is named CUSTOMERS:

public List<Customer> getAll() {
    return jdbcTemplate.query("SELECT * FROM CUSTOMERS", (resultSet, rowNum) -> {
        Customer customer = new Customer();
        customer.setId(resultSet.getLong("id"));
        customer.setName(resultSet.getString("name"));
        customer.setAge(resultSet.getInt("age"));
        return customer;
    });
}

What should I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泛泛之交 2025-02-12 06:29:02

几天来,我和你有同样的担忧。
我通过添加以下内容来解决它:

;TRACE_LEVEL_FILE=3;TRACE_LEVEL_SYSTEM_OUT=3

ie:jdbc:h2:mem:testdb; test_level_file = 3; trace_level_system_out = 3

它有助于知道为什么H2有问题。

通常这是一个关键字问题。
您可以使用non_keywords: commands.html#set_non_keywords

I had the same concern as you for a few days.
I solved it by adding this:

;TRACE_LEVEL_FILE=3;TRACE_LEVEL_SYSTEM_OUT=3

ie : jdbc:h2:mem:testdb;TRACE_LEVEL_FILE=3;TRACE_LEVEL_SYSTEM_OUT=3

It helps to know why H2 has a problem.

Usually it is a keyword problem.
You can ignore it by using NON_KEYWORDS : https://www.h2database.com/html/commands.html#set_non_keywords

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文