H2数据库用户定义的Java函数找不到类 [英] H2 database User defined java function Class not found

查看:185
本文介绍了H2数据库用户定义的Java函数找不到类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我创建用于在H2数据库中注册Java函数的ALIAS时,它会给出未找到的类错误.我正在通过TCP连接运行h2数据库.

When I create an ALIAS for registering the java function in the H2 database, it gives error of class not found. I am running the h2 database on a tcp connection.

样本

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\" ");
    }
}

全部以pacakge名称命名:h2TimeFrame.要测试,

This is all in pacakge name: h2TimeFrame. To test,

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

take the sample class "Function" from the org.h2.samples package. how would you run this class on the server with TCP connection. Changing

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

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

推荐答案

请确保:

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

  • The class is public
  • The method is public and static
  • The class must be available in the classpath of the database engine

来自 H2文档:

在引用方法时,该类必须已经被编译并包含在运行数据库的类路径中.仅支持静态Java方法.类和方法都必须是公共的

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

这篇关于H2数据库用户定义的Java函数找不到类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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