/
Elyumusa
/
SberJavaCourseBeginner
Обзор
Документация
Войти
/
Elyumusa
/
SberJavaCourseBeginner
Код
Запросы
2
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
hw_4
hw5/src/main/java/StudentCoursesRepository.java
25 строк
1 KB
Elyumusa
Домашнее задание 5 выполнено
24 апр 2025, 01:37
24 апр 2025, 01:37
648799b
Код
Авторство
О чём код?
import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; public class StudentCoursesRepository { public static ResultSet selectFromStudentsCoursesTable(Connection con, String selectStudents) throws Exception { PreparedStatement pst = con.prepareStatement(selectStudents); ResultSet rs = pst.executeQuery(); if(!rs.next()){ throw new Exception("No courses found, check the courses table and add some courses"); }else{ System.out.println("Students enrolled successfully! "); return rs; } } public static void createUpdateDeleteFromStudentsCoursesTable(Connection con, String insertStudents, String successMsg) { try (PreparedStatement pst = con.prepareStatement(insertStudents)) { int result = pst.executeUpdate(); System.out.println(successMsg+" "+result); } catch (Exception e) { System.out.println("Error occurred in StudentCoursesRepository: "+e.getMessage()); } } }