Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Database;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.Statement;
- public class Db_tests {
- public static void main(String args[])
- {
- }
- }
- package Database;
- import java.sql.*;
- public class DbAccount {
- private int personID;
- private String login;
- private String password;
- private String permission;
- private String mailAddress;
- private static Connection con = DbConnection.getConnection();
- /********************Insert_do_tabeli***********************/
- /********************Zastonowic_sie_co_z_uczniem***************/
- public DbAccount(int personID, String login, String password, String permission, String mailAddress ) {
- this.personID = personID;
- this.login = login;
- this.password = password;
- this.permission = permission;
- this.mailAddress = mailAddress;
- try {
- String insertTableSQL = "INSERT INTO Konto"
- + "(id_osoby,login, haslo, uprawnienia, adres_mail) VALUES"
- + "(?,?,?,?,?)";
- PreparedStatement preparedStatement = con.prepareStatement(insertTableSQL);
- preparedStatement.setInt(1, this.personID);
- preparedStatement.setString(2, this.login);
- preparedStatement.setString(3, this.password);
- preparedStatement.setString(4, this.permission);
- preparedStatement.setString(5, this.mailAddress);
- preparedStatement.executeUpdate();
- preparedStatement.close();
- } catch (SQLException e) {
- System.out.println("Blad, opis ponizej: ");
- e.printStackTrace();
- }
- }
- /******************Delete_z_bazy*****************************************************/
- static void delete(int personID)
- {
- try {
- Statement statement = con.createStatement();
- statement.execute("Delete from KONTO where ID_osoby="+personID);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- /******************Zmiana hasla*****************************************************/
- static void updatePassword(int personID, String haslo)
- {
- try {
- String insertTableSQL = "Update KONTO set haslo= \"?\" where ID_osoby= ?";
- PreparedStatement preparedStatement = con.prepareStatement(insertTableSQL);
- preparedStatement.setInt(1, personID);
- preparedStatement.setString(2, haslo);
- preparedStatement.executeUpdate();
- preparedStatement.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- /******************Zmiana maila*****************************************************/
- static void updateMail()
- {
- try {
- Statement statement = con.createStatement();
- statement.execute("UPDATE konto Set adres_mail = 'Suchenia' WHERE id_osoby = 3");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- /***********************Getters**********************************************************/
- public int getPersonID() {
- return personID;
- }
- public String getLogin() {
- return login;
- }
- public String getPassword() {
- return password;
- }
- public String getPermission() {
- return permission;
- }
- public String getMailAddress() {
- return mailAddress;
- }
- }
- package Database;
- import java.sql.*;
- public class DbClassroom {
- private int classroomID;
- private String name;
- private int numberOfSeats;
- private String type;
- private String specialEquipment;
- private Connection con = DbConnection.getConnection();
- /*************Getters***************************/
- public int getClassroomID() {
- return classroomID;
- }
- public String getName() {
- return name;
- }
- public int getNumberOfSeats() {
- return numberOfSeats;
- }
- public String getType() {
- return type;
- }
- public String getSpecialEquipment() {
- return specialEquipment;
- }
- }
- package Database;
- import java.sql.*;
- public class DbConnection {
- private static Connection con;
- public static Connection getConnection() {
- try {
- Class.forName("oracle.jdbc.driver.OracleDriver");
- try {
- con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "Dziennik", "haslo");
- } catch (SQLException ex) {
- System.out.println("Failed to create the database connection.");
- }
- } catch (ClassNotFoundException ex) {
- System.out.println("Driver not found.");
- }
- return con;
- }
- }
- package Database;
- import java.sql.*;
- import java.sql.Statement;
- public class DbGroup {
- private int groupID;
- private int teacherID;
- private int classroomID;
- private int classLevel;
- private static Connection con = DbConnection.getConnection();
- /***********Insert_do_tabeli******************************************************/
- public DbGroup(int groupID, int teacherID, int classroomID, int classLevel) {
- this.groupID = groupID;
- this.teacherID = teacherID;
- this.classroomID = classroomID;
- this.classLevel = classLevel;
- try {
- String insertTableSQL = "INSERT INTO Klasa"
- + "(id_klasy, id_nauczyciela, id_sali, numer) VALUES"
- + "(?,?,?,?)";
- PreparedStatement preparedStatement = con.prepareStatement(insertTableSQL);
- preparedStatement.setInt(1, this.groupID);
- preparedStatement.setInt(2, this.teacherID);
- preparedStatement.setInt(3, this.classroomID);
- preparedStatement.setInt(4, this.classLevel);
- preparedStatement.executeUpdate();
- preparedStatement.close();
- } catch (SQLException e) {
- System.out.println("Blad, opis ponizej: ");
- e.printStackTrace();
- }
- }
- /******************Delete_z_bazy*****************************************************/
- static void delete(int groupID)
- {
- try {
- Statement statement = con.createStatement();
- statement.execute("Delete from KLASA where ID_klasy="+groupID);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- /*****************Getters************************************************************/
- public int getGroupID() {
- return groupID;
- }
- public int getTeacherID() {
- return teacherID;
- }
- public int getClassroomID() {
- return classroomID;
- }
- public int getClassLevel() {
- return classLevel;
- }
- }
- package Database;
- import java.sql.*;
- import java.text.SimpleDateFormat;
- public class DbMark {
- private int markID;
- private int subjectID;
- private int studentID;
- private int teacherID;
- private SimpleDateFormat date;
- private String type;
- private int mark;
- private int weight;
- private String description;
- private Connection con = DbConnection.getConnection();
- /*******************GETTERS*****************************/
- public int getMarkID() {
- return markID;
- }
- public int getSubjectID() {
- return subjectID;
- }
- public int getStudentID() {
- return studentID;
- }
- public int getTeacherID() {
- return teacherID;
- }
- public SimpleDateFormat getDate() {
- return date;
- }
- public String getType() {
- return type;
- }
- public int getMark() {
- return mark;
- }
- public int getWeight() {
- return weight;
- }
- public String getDescription() {
- return description;
- }
- }
- package Database;
- import java.sql.*;
- public class DbStudent {
- private int studentID;
- private int groupID;
- private String firstName;
- private String secondName;
- private String personalInfo;
- private static Connection con;
- /***********GETTERS********************/
- public int getStudentID() {
- return studentID;
- }
- public int getGroupID() {
- return groupID;
- }
- public String getFirstName() {
- return firstName;
- }
- public String getSecondName() {
- return secondName;
- }
- public String getPersonalInfo() {
- return personalInfo;
- }
- }
- package Database;
- import java.sql.*;
- public class DbSubject {
- private int subjectID;
- private String name;
- private Connection con = DbConnection.getConnection();
- /**GETTERS**/
- public int getSubjectID() {
- return subjectID;
- }
- public String getName() {
- return name;
- }
- }
- package Database;
- import java.sql.*;
- public class DbTeacher {
- private int teacherID;
- private String firstName;
- private String secondName;
- private String degree;
- private Connection con = DbConnection.getConnection();
- /*****GETTERS**********/
- public int getTeacherID() {
- return teacherID;
- }
- public String getFirstName() {
- return firstName;
- }
- public String getSecondName() {
- return secondName;
- }
- public String getDegree() {
- return degree;
- }
- }
- package Database;
- import java.sql.*;
- import java.text.SimpleDateFormat;
- public class DbTimetable {
- private int timetableID;
- private int groupID;
- private int classroomID;
- private int teacherID;
- private SimpleDateFormat data;
- private int hour;
- private String Subject;
- private static Connection con;
- /*****************GETTERS************************/
- public int getTimetableID() {
- return timetableID;
- }
- public int getGroupID() {
- return groupID;
- }
- public int getClassroomID() {
- return classroomID;
- }
- public int getTeacherID() {
- return teacherID;
- }
- public SimpleDateFormat getData() {
- return data;
- }
- public int getHour() {
- return hour;
- }
- public String getSubject() {
- return Subject;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement