Rewrite the title to: By getting the id of the ResultSet and returning it as a java.sql.Array
P粉905144514
P粉905144514 2023-09-03 18:10:50
0
1
441

I have the following:

 def getIds(name: String): java.sql.Array = { val ids: Array[Integer] = Array() val ps: PreparedStatement = connection.prepareStatement("SELECT id FROM table WHERE name = ?") ps.setString(1, name) val resultSet = ps.executeQuery() while(resultSet.next()) { val currentId = resultSet.getInt(1) ids: currentId } return connection.createArrayOf("INTEGER", ids.toArray) } 

My intention is to use the output of this method into another PreparedStatement, using .setArray(1, )

But I get the following error: java.sql.SQLFeatureNotSupportedException

I'm using MySQL. Already tried INTEGER, INT, BIGINT. But all failed.

P粉905144514
P粉905144514

reply all (1)
P粉265724930

The translated content is:

After research, we found:

So my solution is to create a temporary table containing only the ids:

val idsStatement = connection.prepareStatement( "CREATE TEMPORARY TABLE to_delete_ids SELECT id FROM table WHERE name = ?") idsStatement.setString(1, name) idsStatement.executeUpdate()

Then do an inner join with other statements/queries to achieve the same result:

val statementDeleteUsingIds = connection.prepareStatement( "DELETE to_delete_rows FROM table2 to_delete_rows INNER JOIN to_delete_ids tdi ON tdi.id = to_delete_rows.other_tables_id") statementDeleteUsingIds.executeUpdate()
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!