Store array of strings in MySql via java?
I have a String Array in a java program. I am using jdbc driver to store data in MySql.
There is a reference variable "pstmt" which refers to the prepared statement
now I want to call the following method:
String [] items = {pen, ball, speaker, mic};
pstmt.setArray(1, ....);
where "elements" refers to a String array, but the setArray () method accepts a java.sql.Array instead of a String array.
So how can I convert the "elements" of the string array to java.sql.Array so that I can pass the argument in the above method call.
source to share
As far as I know, setArray(int i, Array x)
and java.sql.Array
which is the interface to retrieve and materialize the ARRAY SQL3 datatype cannot be used the way you want to use it.
By the way, the Array implementation is optional as per the JDBC spec and I don't think the MySQL driver provides the implementation.
source to share