Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package quizapp.model;
- import java.sql.*;
- import quizpp.util.DatabaseManager;
- public class AddAccount {
- private DatabaseManager db = new DatabaseManager();
- public boolean insertStaffAccount(String staffID, String staffFN, String staffLN, String staffE) {
- String insertStaffTableSQL = "INSERT INTO 16agileteam1db.staff "
- + "VALUES(" + staffID + ");";
- String insertProfileTableSQL = "INSERT INTO 16agileteam1db.profile_details(staff_id_number, first_name, last_name, email, soul) "
- + "VALUES(" + staffID + ",'" + staffFN + "','" + staffLN + "','" + staffE + "','staff');";
- try(Connection connection = db.getConnection(); Statement statement = connection.createStatement()) {
- statement.addBatch(insertStaffTableSQL);
- statement.addBatch(insertProfileTableSQL);
- statement.executeBatch();
- } catch (ClassNotFoundException | SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- public boolean insertStudentAccount(String matricN, String studentFN, String studentLN, String studentE) {
- String driverName = "com.mysql.jdbc.Driver";
- String connectionUrl = "jdbc:mysql://silva.computing.dundee.ac.uk:3306/";
- String dbName = "16agileteam1db";
- String userID = "16agileteam1";
- String password = "8320.at1.0238";
- try {
- Class.forName(driverName);
- } catch (ClassNotFoundException e) {
- }
- Connection connection = null;
- Statement statement = null;
- Statement statement2 = null;
- String insertStudentTableSQL = "INSERT INTO 16agileteam1db.student (matriculation_number) "
- + "VALUES(" + matricN + ");";
- String insertProfileTableSQL = "INSERT INTO 16agileteam1db.profile_details(matriculation_number, first_name, last_name, email, soul) "
- + "VALUES(" + matricN + ",'" + studentFN + "','" + studentLN + "','" + studentE + "','student');";
- try {
- connection = DriverManager.getConnection(connectionUrl + dbName, userID, password);
- statement = connection.createStatement();
- statement2 = connection.createStatement();
- statement.execute(insertStudentTableSQL);
- statement2.execute(insertProfileTableSQL);
- connection.close();
- return true;
- } catch (Exception e) {
- e.getMessage();
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement