@@ -0,0 +1,2826 @@
+package classpackage;%0A%0Aimport java.sql.Connection;%0Aimport java.sql.DriverManager;%0Aimport java.sql.ResultSet;%0Aimport java.sql.Statement;%0Aimport java.util.List;%0A%0Apublic class template %7B%0A%0A    // This 'should' be either saved in a common class for just static final queries or we just saved it as final in the methods they are being used. In this case i am saving outside to be simpler to find.%0A    static final String sf_getAllEmployeesQuery = %22SELECT * %22;%0A%0A    //Either use the name %22db%22, or %22connection%22, i personally use db and rarely connection, but any other name could end up being misleading. This should also be in a class thats easily rememebred and accessed by every class so that we all use the same connection and keep it alive.%0A    public static Connection db;%0A%0A%0A    // This variable should be saved in a common class with all the other variables containing a collection of the object in question, like %22s_orderListSavedOnClient%22.. and probably use a different name, though for exaplaining purposes, i am naming it like this:%0A    static List%3CEmployee%3E s_employeeListSavedOnClient;%0A%0A    // Named _main to not conflict with a main if there is already in our program. Though our main main should have these functions: and _init_() should be on the top of everything in our main.%0A    public static void _main(String%5B%5D args) throws Exception %7B%0A        _init_();%0A        updateEmployeeList();%0A    %7D%0A%0A    // This only has to be called once and at the startup of our application.. probaly the first function in our main(). Also, we should set our username and password. I actually don't mind if we use my username and password.%0A    private static void _init_() throws Exception%0A    %7B%0A        String dbDriver = %22com.mysql.jdbc.Driver%22;%0A        Class.forName(dbDriver);%0A        String databasenavn = %22jdbc:mysql://mysql.stud.iie.ntnu.no:3306/%22 + consts.username + %22?user=%22 + consts.username + %22&password=%22 + consts.passord;%0A        db = DriverManager.getConnection(databasenavn);%0A    %7D%0A%0A%0A%0A    // Call this function whenever another client updates or when we init to get the list. NOTE: we should actually change the class Employee to have %22passhash%22 instead of %22startPassword%22, as we should not have the password saved in memory. (we shouldnt have the hash either.. but this is a school thing, so we can keep it. The hash is generated when we enter the password and the salt.%0A    private static void updateEmployeeList() throws Exception %7B%0A        s_employeeListSavedOnClient.clear();%0A        Statement setning = db.createStatement();%0A        ResultSet res = setning.executeQuery(sf_getAllEmployeesQuery);%0A        while (res.next())%0A            s_employeeListSavedOnClient.add(new Employee(res.getInt(%22person_id%22), res.getString(%22username%22), res.getInt(%22pos_id%22), res.getDouble(%22salary%22), res.getString(%22passhash%22)));%0A    %7D%0A%7D%0A

Create template.java