如何创建一个 java.sql.Array 的字符串?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4108679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I create a java.sql.Array of Strings?
提问by Edu
Possible Duplicate:
How to create ArrayList (ArrayList<T>) from array (T[]) in Java
I have:
我有:
String[] time = {"22:22:22","22:22:23"};
Array asd = null;
How can I put something like asd=time
?
我怎么能放类似的东西asd=time
?
回答by Grodriguez
I assume that what you actually need is a java.sql.Array
, since you mention jdbc and setArray
in some of your comments.
我假设你真正需要的是 a java.sql.Array
,因为你提到了 jdbc 和setArray
你的一些评论。
Three options:
三个选项:
- Try
Connection.createArrayOf()
. This might or might not be available, depending on the JDBC driver you are using. - Write your own class that implements
java.sql.Array
. Here is an examplefor PostgreSQL. - Some implementations, such as Oracle's, provide utility methods to work with arrays. Check the documentation of your JDBC driver.
- 试试
Connection.createArrayOf()
。这可能可用也可能不可用,具体取决于您使用的 JDBC 驱动程序。 - 编写自己的类来实现
java.sql.Array
. 这是PostgreSQL的示例。 - 一些实现,例如Oracle 的,提供了使用数组的实用方法。检查 JDBC 驱动程序的文档。
回答by Alan Geleynse
The Array
class is not an actual array. Instead it is a helper class that has static methods to help with arrays.
的Array
类不是一个实际的数组。相反,它是一个辅助类,具有用于帮助处理数组的静态方法。
You may be looking to use ArrayList
or something like it. You could use it using List<String> asd = Arrays.asList(time)
您可能正在寻找使用ArrayList
或类似的东西。你可以使用它List<String> asd = Arrays.asList(time)
回答by EboMike
Array
is an interface, not a class. Are you referring to ArrayList
?!
Array
是一个接口,而不是一个类。你指的是ArrayList
?!
Here is your answer: Create ArrayList from array
这是您的答案:从数组创建 ArrayList
new ArrayList<Element>(Arrays.asList(array))
new ArrayList<Element>(Arrays.asList(array))