转换java.util.List< String>到java.sql.Array [英] Convert java.util.List<String> into java.sql.Array
问题描述
如何将 java.util.List< String>
实例转换为 java.sql.Array
?
推荐答案
使用 connection.createArrayOf(...)
例如:
final String[] data = yourList.toArray(new String[yourList.size()]);
final java.sql.Array sqlArray = connection.createArrayOf(typeName, data);
statement.setArray(position, sqlArray);
其中typeName为:
Where typeName is:
数组元素映射到的类型的SQL名称。 typeName是特定于数据库的名称,可以是此数据库支持的内置类型,用户定义类型或标准SQL类型的名称。这是Array.getBaseTypeName返回的值
the SQL name of the type the elements of the array map to. The typeName is a database-specific name which may be the name of a built-in type, a user-defined type or a standard SQL type supported by this database. This is the value returned by Array.getBaseTypeName
如评论中所述,这是是Java 1.6。对于旧版本,您无法以独立于驱动程序的方式创建此版本。你只应该获取数组,而不是创建它们。如果你愿意,你可以从你的jdbc驱动程序中实例化实现类,但这是不可移植的。
As noted in the comments, this is Java 1.6. For older versions you can't create this in a driver-independent way. You are only supposed to get arrays, not create them. If you want to, you can instantiate the implementing class from your jdbc driver, but this is non-portable.
这篇关于转换java.util.List< String>到java.sql.Array的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!