gpt4 book ai didi

java - H2 数据库用户定义的 java 函数类未找到

转载 作者:行者123 更新时间:2023-11-30 11:28:22 25 4
gpt4 key购买 nike

当我创建一个用于在 H2 数据库中注册 java 函数的别名时,它给出了找不到类的错误。我在 tcp 连接上运行 h2 数据库。

示例,

public class TimeFrame { 
public static void main(String... args) throws Exception {
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:tcp://MYIP:9092/~/test", "sa", "");
Statement stat = conn.createStatement();

//Setup Table
stat.execute("DROP TABLE IF EXISTS timeframe");
stat.execute("CREATE TABLE timeframe (last_updated TIMESTAMP, ip int");
stat.execute("CREATE ALIAS IF NOT EXISTS SLIDEWINDOW FOR \"h2TimeFrame.TimeFrame.slidewindow\" ");
}
}

这一切都在包名中:h2TimeFrame。测试,

从 org.h2.samples 包中获取示例类“Function”。您将如何在具有 TCP 连接的服务器上运行此类。改变

  Connection conn = DriverManager.getConnection("jdbc:h2:~/test", "sa", "");

  Connection conn = DriverManager.getConnection("jdbc:h2:tcp://IPADDRESS:9092/~/test", "sa", "");

最佳答案

确保:

  • 类是public
  • 该方法是publicstatic
  • 该类必须在数据库引擎的类路径中可用

    来自 H2 Docs :

    When referencing a method, the class must already be compiled and included in the classpath where the database is running. Only static Java methods are supported; both the class and the method must be public

关于java - H2 数据库用户定义的 java 函数类未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18896093/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com