public void runQuery(String url, String sql) {
try (Connection connection = DriverManager.getConnection(url);
PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
// ... add parameters to the SQL query using PreparedStatement methods:
// setInt, setString, etc.
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
// ... do something with result set
}
}
} catch (SQLException e) {
// ... handle SQL exception
}
}