Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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 ?

like image 713
Edu Avatar asked Nov 05 '10 17:11

Edu


People also ask

What is an array how to declare an array in java?

Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value. To declare an array, define the variable type with square brackets: String[] cars; We have now declared a variable that holds an array of strings.

How do you create an array in SQL?

Define arrays as SQL variables. Use the ARRAY_AGG built-in function in a cursor declaration, to assign the rows of a single-column result table to elements of an array. Use the cursor to retrieve the array into an SQL out parameter. Use an array constructor to initialize an array.

How do you count duplicate elements in a string array in Java?

Put it in a map with count as value. Then simply count strings with count > 1 . Show activity on this post. Convert it to a set.. Then (length_of_Set - length_of_Array) is your count of duplicate elements.


2 Answers

I assume that what you actually need is a java.sql.Array, since you mention jdbc and setArray in some of your comments.

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 example for PostgreSQL.
  3. Some implementations, such as Oracle's, provide utility methods to work with arrays. Check the documentation of your JDBC driver.
like image 127
Grodriguez Avatar answered Sep 19 '22 17:09

Grodriguez


The Array class is not an actual array. Instead it is a helper class that has static methods to help with arrays.

You may be looking to use ArrayList or something like it. You could use it using List<String> asd = Arrays.asList(time)

like image 41
Alan Geleynse Avatar answered Sep 21 '22 17:09

Alan Geleynse