Advertisement
Guest User

Untitled

a guest
Nov 25th, 2018
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.33 KB | None | 0 0
  1. package Database;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.Statement;
  6.  
  7. public class Db_tests {
  8.     public static void main(String args[])
  9.     {
  10.  
  11.  
  12.     }
  13. }
  14.  
  15. package Database;
  16. import java.sql.*;
  17.  
  18. public class DbAccount {
  19.  
  20.     private int personID;
  21.     private String login;
  22.     private String password;
  23.     private String permission;
  24.     private String mailAddress;
  25.     private static Connection con = DbConnection.getConnection();
  26.  
  27.  
  28.     /********************Insert_do_tabeli***********************/
  29.     /********************Zastonowic_sie_co_z_uczniem***************/
  30.     public DbAccount(int personID, String login, String password, String permission, String mailAddress ) {
  31.  
  32.         this.personID = personID;
  33.         this.login = login;
  34.         this.password = password;
  35.         this.permission = permission;
  36.         this.mailAddress = mailAddress;
  37.  
  38.         try {
  39.             String insertTableSQL = "INSERT INTO Konto"
  40.                     + "(id_osoby,login, haslo, uprawnienia, adres_mail) VALUES"
  41.                     + "(?,?,?,?,?)";
  42.             PreparedStatement preparedStatement = con.prepareStatement(insertTableSQL);
  43.             preparedStatement.setInt(1, this.personID);
  44.             preparedStatement.setString(2, this.login);
  45.             preparedStatement.setString(3, this.password);
  46.             preparedStatement.setString(4, this.permission);
  47.             preparedStatement.setString(5, this.mailAddress);
  48.             preparedStatement.executeUpdate();
  49.             preparedStatement.close();
  50.         } catch (SQLException e) {
  51.             System.out.println("Blad, opis ponizej: ");
  52.             e.printStackTrace();
  53.         }
  54.     }
  55.     /******************Delete_z_bazy*****************************************************/
  56.     static void delete(int personID)
  57.     {
  58.         try {
  59.             Statement statement = con.createStatement();
  60.             statement.execute("Delete from KONTO where ID_osoby="+personID);
  61.         } catch (SQLException e) {
  62.             e.printStackTrace();
  63.         }
  64.     }
  65.     /******************Zmiana hasla*****************************************************/
  66.     static void updatePassword(int personID, String haslo)
  67.     {
  68.         try {
  69.             String insertTableSQL = "Update KONTO set haslo= \"?\" where ID_osoby= ?";
  70.             PreparedStatement preparedStatement = con.prepareStatement(insertTableSQL);
  71.             preparedStatement.setInt(1, personID);
  72.             preparedStatement.setString(2, haslo);
  73.             preparedStatement.executeUpdate();
  74.             preparedStatement.close();
  75.  
  76.  
  77.         } catch (SQLException e) {
  78.             e.printStackTrace();
  79.         }
  80.     }
  81.     /******************Zmiana maila*****************************************************/
  82.     static void updateMail()
  83.     {
  84.         try {
  85.             Statement statement = con.createStatement();
  86.             statement.execute("UPDATE konto Set adres_mail = 'Suchenia' WHERE id_osoby = 3");
  87.         } catch (SQLException e) {
  88.             e.printStackTrace();
  89.         }
  90.     }
  91.  
  92.  
  93.     /***********************Getters**********************************************************/
  94.     public int getPersonID() {
  95.         return personID;
  96.     }
  97.  
  98.     public String getLogin() {
  99.         return login;
  100.     }
  101.  
  102.     public String getPassword() {
  103.         return password;
  104.     }
  105.  
  106.     public String getPermission() {
  107.         return permission;
  108.     }
  109.  
  110.     public String getMailAddress() {
  111.         return mailAddress;
  112.     }
  113. }
  114.  
  115. package Database;
  116. import java.sql.*;
  117.  
  118. public class DbClassroom {
  119.  
  120.  
  121.     private int classroomID;
  122.     private String name;
  123.     private int numberOfSeats;
  124.     private String type;
  125.     private String specialEquipment;
  126.     private Connection con = DbConnection.getConnection();
  127.  
  128.  
  129.     /*************Getters***************************/
  130.     public int getClassroomID() {
  131.         return classroomID;
  132.     }
  133.  
  134.     public String getName() {
  135.         return name;
  136.     }
  137.  
  138.     public int getNumberOfSeats() {
  139.         return numberOfSeats;
  140.     }
  141.  
  142.     public String getType() {
  143.         return type;
  144.     }
  145.  
  146.     public String getSpecialEquipment() {
  147.         return specialEquipment;
  148.     }
  149. }
  150.  
  151. package Database;
  152.  
  153. import java.sql.*;
  154.  
  155. public class DbConnection {
  156.  
  157.     private static Connection con;
  158.  
  159.     public static Connection getConnection() {
  160.         try {
  161.             Class.forName("oracle.jdbc.driver.OracleDriver");
  162.             try {
  163.                 con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "Dziennik", "haslo");
  164.             } catch (SQLException ex) {
  165.                 System.out.println("Failed to create the database connection.");
  166.             }
  167.         } catch (ClassNotFoundException ex) {
  168.             System.out.println("Driver not found.");
  169.         }
  170.         return con;
  171.     }
  172. }
  173.  
  174.  
  175. package Database;
  176. import java.sql.*;
  177. import java.sql.Statement;
  178. public class DbGroup {
  179.  
  180.     private int groupID;
  181.     private int teacherID;
  182.     private int classroomID;
  183.     private int classLevel;
  184.  
  185.     private static Connection con = DbConnection.getConnection();
  186.  
  187.     /***********Insert_do_tabeli******************************************************/
  188.     public DbGroup(int groupID, int teacherID, int classroomID, int classLevel) {
  189.         this.groupID = groupID;
  190.         this.teacherID = teacherID;
  191.         this.classroomID = classroomID;
  192.         this.classLevel = classLevel;
  193.         try {
  194.             String insertTableSQL = "INSERT INTO Klasa"
  195.                     + "(id_klasy, id_nauczyciela, id_sali, numer) VALUES"
  196.                     + "(?,?,?,?)";
  197.             PreparedStatement preparedStatement = con.prepareStatement(insertTableSQL);
  198.             preparedStatement.setInt(1, this.groupID);
  199.             preparedStatement.setInt(2, this.teacherID);
  200.             preparedStatement.setInt(3, this.classroomID);
  201.             preparedStatement.setInt(4, this.classLevel);
  202.             preparedStatement.executeUpdate();
  203.             preparedStatement.close();
  204.         } catch (SQLException e) {
  205.             System.out.println("Blad, opis ponizej: ");
  206.             e.printStackTrace();
  207.         }
  208.     }
  209.     /******************Delete_z_bazy*****************************************************/
  210.     static void delete(int groupID)
  211.     {
  212.         try {
  213.             Statement statement = con.createStatement();
  214.             statement.execute("Delete from KLASA where ID_klasy="+groupID);
  215.         } catch (SQLException e) {
  216.             e.printStackTrace();
  217.         }
  218.     }
  219.  
  220.     /*****************Getters************************************************************/
  221.     public int getGroupID() {
  222.         return groupID;
  223.     }
  224.  
  225.     public int getTeacherID() {
  226.         return teacherID;
  227.     }
  228.  
  229.     public int getClassroomID() {
  230.         return classroomID;
  231.     }
  232.  
  233.     public int getClassLevel() {
  234.         return classLevel;
  235.     }
  236. }
  237.  
  238. package Database;
  239. import java.sql.*;
  240. import java.text.SimpleDateFormat;
  241.  
  242. public class DbMark {
  243.  
  244.     private int markID;
  245.     private int subjectID;
  246.     private int studentID;
  247.     private int teacherID;
  248.     private SimpleDateFormat date;
  249.     private String type;
  250.     private int mark;
  251.     private int weight;
  252.     private String description;
  253.     private Connection con = DbConnection.getConnection();
  254.  
  255.     /*******************GETTERS*****************************/
  256.     public int getMarkID() {
  257.         return markID;
  258.     }
  259.  
  260.     public int getSubjectID() {
  261.         return subjectID;
  262.     }
  263.  
  264.     public int getStudentID() {
  265.         return studentID;
  266.     }
  267.  
  268.     public int getTeacherID() {
  269.         return teacherID;
  270.     }
  271.  
  272.     public SimpleDateFormat getDate() {
  273.         return date;
  274.     }
  275.  
  276.     public String getType() {
  277.         return type;
  278.     }
  279.  
  280.     public int getMark() {
  281.         return mark;
  282.     }
  283.  
  284.     public int getWeight() {
  285.         return weight;
  286.     }
  287.  
  288.     public String getDescription() {
  289.         return description;
  290.     }
  291. }
  292.  
  293.  
  294. package Database;
  295. import java.sql.*;
  296.  
  297. public class DbStudent {
  298.  
  299.     private int studentID;
  300.     private int groupID;
  301.     private String firstName;
  302.     private String secondName;
  303.     private String personalInfo;
  304.     private static Connection con;
  305.  
  306.     /***********GETTERS********************/
  307.     public int getStudentID() {
  308.         return studentID;
  309.     }
  310.     public int getGroupID() {
  311.         return groupID;
  312.     }
  313.     public String getFirstName() {
  314.         return firstName;
  315.     }
  316.     public String getSecondName() {
  317.         return secondName;
  318.     }
  319.     public String getPersonalInfo() {
  320.         return personalInfo;
  321.     }
  322. }
  323.  
  324.  
  325.  
  326. package Database;
  327. import java.sql.*;
  328. public class DbSubject {
  329.  
  330.     private int subjectID;
  331.     private String name;
  332.     private Connection con = DbConnection.getConnection();
  333.  
  334.     /**GETTERS**/
  335.     public int getSubjectID() {
  336.         return subjectID;
  337.     }
  338.  
  339.     public String getName() {
  340.         return name;
  341.     }
  342. }
  343.  
  344.  
  345.  
  346.  
  347. package Database;
  348. import java.sql.*;
  349. public class DbTeacher {
  350.     private int teacherID;
  351.     private String firstName;
  352.     private String secondName;
  353.     private String degree;
  354.     private Connection con = DbConnection.getConnection();
  355.  
  356.  
  357.  
  358.     /*****GETTERS**********/
  359.     public int getTeacherID() {
  360.         return teacherID;
  361.     }
  362.  
  363.     public String getFirstName() {
  364.         return firstName;
  365.     }
  366.  
  367.     public String getSecondName() {
  368.         return secondName;
  369.     }
  370.  
  371.     public String getDegree() {
  372.         return degree;
  373.     }
  374. }
  375.  
  376.  
  377.  
  378.  
  379.  
  380. package Database;
  381. import java.sql.*;
  382. import java.text.SimpleDateFormat;
  383.  
  384. public class DbTimetable {
  385.  
  386.     private int timetableID;
  387.     private int groupID;
  388.     private int classroomID;
  389.     private int teacherID;
  390.     private SimpleDateFormat data;
  391.     private int hour;
  392.     private String Subject;
  393.     private static Connection con;
  394.  
  395.  
  396.  
  397.     /*****************GETTERS************************/
  398.     public int getTimetableID() {
  399.         return timetableID;
  400.     }
  401.  
  402.     public int getGroupID() {
  403.         return groupID;
  404.     }
  405.  
  406.     public int getClassroomID() {
  407.         return classroomID;
  408.     }
  409.  
  410.     public int getTeacherID() {
  411.         return teacherID;
  412.     }
  413.  
  414.     public SimpleDateFormat getData() {
  415.         return data;
  416.     }
  417.  
  418.     public int getHour() {
  419.         return hour;
  420.     }
  421.  
  422.     public String getSubject() {
  423.         return Subject;
  424.     }
  425. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement