D
D
Delwin2015-08-22 12:28:22
Microsoft
Delwin, 2015-08-22 12:28:22

Sql.Array in mssql jdbc4 java.sql.SQLFeatureNotSupportedException: This operation is not supported Bug?

It is necessary to make a selection on the MSSQL database of the form select pathstr from edo_file where id in (?)
where ? this is an array of IDs of the required entries.
In software, one of the classes returns me a regular array of type Long[], for example

idArray = new Long[] {1003215L,100358L,100456L};

Using them, you need to find the value of "pathstr"
A piece of code:
Long[] idArray = new Long[] {1003215L,100358L,100456L};
String sql = "select pathstr from edo_file where id in (?)";
java.sql.Array idArraySql = con.createArrayOf("NUMERIC",idArray);
PreparedStatement ps = con.prepareStatement(sql);
ps.setArray(1,idArraySql);
ResultSet rs = ps.executeQuery();

I catch an exception on the con.createArrayOf method java.sql.SQLFeatureNotSupportedException
: This operation is not supported
Decompiling the SQLServerConnection class of the Microsoft jdbc5 library showed the following:
public Array createArrayOf(String var1, Object[] var2) throws SQLException {
     DriverJDBCVersion.checkSupportsJDBC4();
     throw new SQLFeatureNotSupportedException(SQLServerException.getErrString("R_notSupported"));
 }

Who faced such a task? Are there any ways to insert an array into a PreparedStatment without type encoding elements
StringBuilder sb = new StringBuilder();
for(int i=0;i<idArray.length;i++){
    sb.append("'");
    sb.append(idArray[i]);
    sb.append("'");
    if (i<idArray.length-1){
        sb.append(",");
    }
}
sql=sql.replace("?",sb.toString());

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question