Advertisement
Guest User

Main2

a guest
Feb 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import java.sql.*;
  2. import java.util.Scanner;
  3.  
  4. public class Main2 {
  5.  
  6. private static final String QUERY1 = "SELECT * FROM departments";
  7.  
  8. public static void main(String[] args) {
  9. showAllDepartments();
  10.  
  11. Scanner scanner = new Scanner(System.in);
  12. int id = scanner.nextInt();
  13. showWorkersFromDepartmentId(id);
  14. }
  15.  
  16. public static void showAllDepartments() {
  17. try (Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/exam2poprawa?useSSL=false", "root", "coderslab")) {
  18. PreparedStatement ps = con.prepareStatement(QUERY1);
  19.  
  20. ResultSet resultSet = ps.executeQuery();
  21. while (resultSet.next()) {
  22. System.out.println(resultSet.getInt("id") + " " + resultSet.getString("name"));
  23. }
  24.  
  25. } catch (SQLException e) {
  26. e.printStackTrace();
  27. }
  28. }
  29.  
  30. public static void showWorkersFromDepartmentId(int id) {
  31.  
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement