我正在使用 jaydebea ,它使用jpype加载FileMaker的JDBC驱动程序和拉动数据。

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

jdbc文档(第55页)它列出以下功能:

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

getcolumns

getColumnPrivileges

getmetadata

gettypeinfo

gettables

gettabletypes

任何想法如何从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()
.

更新:

这里有一些进步,看起来它应该工作,但我得到了下面的错误。任何想法?

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

有帮助吗?

解决方案

好的,谢谢埃尔塔巴和胡安梅拉多,我认为它!

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

这是工作代码:

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']
.

其他提示

从结果集javadoc:

public ResultSet getTables(String catalog,
                       String schemaPattern,
                       String tableNamePattern,
                       String[] types)
                throws SQLException
.

您需要将四个参数传递给方法。我不是Python开发人员,但在Java中我使用:

ResultSet rs = metadata.getTables(null, "public", "%" ,new String[] {"TABLE"} );
.

以在架构中获取所有表(且只有表格)。

问候。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top