微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将java.util.List转换为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是:

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驱动程序实例化实现类,但这是不可移植的.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐