Last active
July 4, 2023 07:25
-
-
Save kasramp/e114850509b5a84c3e59 to your computer and use it in GitHub Desktop.
Option-1 (Single insert with making connection for each insert)
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 insertStudents(List<Student> students) { | |
String statement = "INSERT INTO student VALUES(?,?,?)"; | |
for (int i = 0; i < students.size(); i++) { | |
Student student = students.get(i); | |
try (Connection connection = config.getConnection()) { | |
try (PreparedStatement ps = connection.prepareStatement(statement)) { | |
int j = 0; | |
ps.setString(++j, student.getGuid()); | |
ps.setString(++j, student.getName()); | |
ps.setInt(++j, student.getId()); | |
ps.executeUpdate(); | |
} | |
} 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