多值字段的UCanAccess中的解决方法:“转换中的数据类型不兼容:来自SQL类型OTHER"? [英] Workaround in UCanAccess for multi-value fields: "incompatible data type in conversion: from SQL type OTHER"?

查看:472
本文介绍了多值字段的UCanAccess中的解决方法:“转换中的数据类型不兼容:来自SQL类型OTHER"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用UCanAccess查询MS Access .accdb文件.除查询多值字段外,其他所有操作都很好.例如,那些在MS Access设计视图中的表的行源"字段的查找"选项卡中具有条目的条目.当我尝试输出结果时,我的代码崩溃了:

I am trying to use UCanAccess to query a MS Access .accdb file. Everything works great, except when I query multi-value fields. For example those that have entries in the Row Source of a table field's Lookup tab in design view in MS Access. My code crashes when I try to output the result:

ResultSet rslt = stmt.executeQuery("SELECT [singleValue], [multiValue] FROM [TableName];");
int count = 0;
while (rslt.next())
    System.out.println(count++ + "\t" + rslt.getString(1) + "\t" + rslt.getString(2));

可以很好地返回ResultSet,并且可以正常打印singleValue,但是如果我尝试从ResultSet中打印multiValue,则会引发以下错误:

The ResultSet is returned fine, and the singleValue prints fine, but the following error is thrown if I try to print the multiValue from the ResultSet:

线程主"中的异常net.ucanaccess.jdbc.UcanaccessSQLException:转换中的数据类型不兼容:从SQL类型OTHER到java.lang.String,值:org.hsqldb.types.JavaObjectData的实例

我已经尝试查询存储在.accdb中的查询,但是它不起作用,因为它只会触发原始查询,并返回相同的ResultSet.

Exception in thread "main" net.ucanaccess.jdbc.UcanaccessSQLException: incompatible data type in conversion: from SQL type OTHER to java.lang.String, value: instance of org.hsqldb.types.JavaObjectData

I have tried querying a query that is stored in the .accdb, but that does not work, because it just triggers the original query, and returns the same ResultSet.

我缺少一些简单的东西吗?还是UCanAccess无法处理的事情?

Am I missing something simple or is this something UCanAccess can not handle?

推荐答案

这是我所见过的第一个问题. 您可以在ucanaccess网站的入门"标签(在页面末尾)中看到有关UCanAccess的复杂类型用法的示例. 这是一个junit测试用例: https ://sourceforge.net/p/ucanaccess/code/HEAD/tree/ucanaccess/trunk/src/test/java/net/ucanaccess/test/ComplexTest.java (请参见testComplex方法).

This is the first question about it I have ever seen. You can see an example of the complex types usage with UCanAccess in the ucanaccess web site, tab "Getting Started" (at the end of the page). Here's a junit test case: https://sourceforge.net/p/ucanaccess/code/HEAD/tree/ucanaccess/trunk/src/test/java/net/ucanaccess/test/ComplexTest.java (see the testComplex method).

尤其是您不能调用rslt.getString(2),而必须使用rslt.getObject(2). 您将获得一个ucanaccess数据包装器. 如果您想获取描述数据内容的字符串,则可以使用 rslt.getObject(2).toString(). 包装类是:

In particular you can't call rslt.getString(2) but have to use rslt.getObject(2) . You'll get a ucanaccess wrapper of your data. If you wanted to get string that described the data content you can use rslt.getObject(2).toString(). The wrapping classes are:

net.ucanaccess.complex.Attachment,
net.ucanaccess.complex.SingleValue,
net.ucanaccess.complex.Version.

在您的示例中,rslt.getObject(2)应该返回net.ucanaccess.complex.SingleValue的数组. 然后,您可以在每个数组元素上调用方法singleValue.getValue()以获取包装的值.

In your example, rslt.getObject(2) should return an array of net.ucanaccess.complex.SingleValue. Then you can call the method singleValue.getValue() on each array element to get the wrapped value.

这篇关于多值字段的UCanAccess中的解决方法:“转换中的数据类型不兼容:来自SQL类型OTHER"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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