Last active
July 4, 2023 12:23
-
-
Save kasramp/3a0d116451e7be7b0605 to your computer and use it in GitHub Desktop.
Option-5 (Unnest insertion)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void insertNames(List<String> names) { | |
try (Connection connection = config.getConnection()) { | |
PreparedStatement statement = connection.prepareStatement("INSERT INTO student (name) SELECT * FROM UNNEST(?)"); | |
statement.setArray(1, connection.createArrayOf("text", names.toArray(new String[names.size()]))); | |
statement.execute(); | |
} catch (SQLException e) { | |
throw new RuntimeException(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment