使用 JPype - 如何访问 JDBC 元数据函数

Gre*_*reg 3 python jdbc jpype jaydebeapi

我正在使用JayDeBeAPI,它使用 JPype 加载 FileMaker 的 JDBC 驱动程序并提取数据。

但我也希望能够获得数据库中所有表的列表。

JDBC 文档(第 55 页)中,列出了以下函数:

JDBC 客户端驱动程序支持以下元数据功能:

获取列

获取列权限

获取元数据

获取类型信息

获取表

获取表类型

我有什么想法可以从 JPype 或 JayDeBeAPI 调用它们吗?

如果有帮助,这是我当前的代码:

import jaydebeapi
import jpype

jar = r'/opt/drivers/fmjdbc.jar'
args='-Djava.class.path=%s' % jar
jvm_path = jpype.getDefaultJVMPath()
jpype.startJVM(jvm_path, args)

conn = jaydebeapi.connect('com.filemaker.jdbc.Driver',
        SETTINGS['SOURCE_URL'], SETTINGS['SOURCE_UID'], SETTINGS['SOURCE_PW'])
curs = conn.cursor()

#Sample Query:
curs.execute("select * from table")
result_rows = curs.fetchall()
Run Code Online (Sandbox Code Playgroud)

更新:

这是一些进展,看起来应该可以工作,但我收到以下错误。有任何想法吗?

> conn.jconn.metadata.getTables()
*** RuntimeError: No matching overloads found. at src/native/common/jp_method.cpp:121
Run Code Online (Sandbox Code Playgroud)

Gre*_*reg 5

好的,多亏了 eltabo 和 Juan Mellado,我明白了!

我只需传入正确的参数来匹配方法签名。

这是工作代码:

import jaydebeapi
import jpype

jar = r'/opt/drivers/fmjdbc.jar'
args='-Djava.class.path=%s' % jar
jvm_path = jpype.getDefaultJVMPath()
jpype.startJVM(jvm_path, args)

conn = jaydebeapi.connect('com.filemaker.jdbc.Driver',
        SETTINGS['SOURCE_URL'], SETTINGS['SOURCE_UID'], SETTINGS['SOURCE_PW'])
results = source_conn.jconn.getMetaData().getTables(None, None, "%", None)

#I'm not sure if this is how to read the result set, but jaydebeapi's cursor object
# has a lot of logic for getting information out of a result set, so let's harness
# that.
table_reader_cursor = source_conn.cursor()
table_reader_cursor._rs = results
read_results = table_reader_cursor.fetchall()
#get just the table names
[row[2] for row in read_results if row[3]=='TABLE']
Run Code Online (Sandbox Code Playgroud)