如何创建一个 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 04:47:25  来源:igfitidea点击:

How can I create a java.sql.Array of Strings?

javasqljdbccasting

提问by Edu

Possible Duplicate:
How to create ArrayList (ArrayList<T>) from array (T[]) in Java

可能的重复:
如何在 Java 中从数组 (T[]) 创建 ArrayList (ArrayList<T>)

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 setArrayin some of your comments.

我假设你真正需要的是 a java.sql.Array,因为你提到了 jdbc 和setArray你的一些评论。

Three options:

三个选项:

  1. Try Connection.createArrayOf(). This might or might not be available, depending on the JDBC driver you are using.
  2. Write your own class that implements java.sql.Array. Here is an examplefor PostgreSQL.
  3. Some implementations, such as Oracle's, provide utility methods to work with arrays. Check the documentation of your JDBC driver.
  1. 试试Connection.createArrayOf()。这可能可用也可能不可用,具体取决于您使用的 JDBC 驱动程序。
  2. 编写自己的类来实现java.sql.Array. 这是PostgreSQL的示例
  3. 一些实现,例如Oracle 的,提供了使用数组的实用方法。检查 JDBC 驱动程序的文档。

回答by Alan Geleynse

The Arrayclass 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 ArrayListor something like it. You could use it using List<String> asd = Arrays.asList(time)

您可能正在寻找使用ArrayList或类似的东西。你可以使用它List<String> asd = Arrays.asList(time)

回答by EboMike

Arrayis 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))