Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static UserAccountList instance;
- private ArrayList<user> userList;
- user newUser = null;
- int currentUser;
- protected UserAccountList() throws IOException {
- this.userList = new ArrayList<>();
- readDatabase();
- }
- public static void main(String[] args) throws IOException{
- ArrayList<user> userList1 = new UserAccountList().getUserList();
- for(int i=0;i<userList1.size();i++){
- System.out.println(userList1.get(i).getUsername());
- }
- }
- public ArrayList getUserList() throws IOException {
- return this.userList;
- }
- public static UserAccountList getInstance() throws IOException {
- if (instance == null) {
- instance = new UserAccountList();
- }
- return instance;
- }
- private void readDatabase() throws IOException {
- PreparedStatement ps;
- ResultSet rs;
- String query = "SELECT * FROM `user`" ;
- try{
- ps = MyConnection.getConnection().prepareStatement(query);
- rs = ps.executeQuery();
- while(rs.next() != false){
- String uname = rs.getString("username");
- String pass = rs.getString("password");
- String fname = rs.getString("firstname");
- String lname = rs.getString("lastname");
- String email = rs.getString("email");
- String uni = rs.getString("university");
- String course = rs.getString("course");
- user newUser = new user(fname, lname, uname, pass, email, uni, course);
- addUser(newUser);
- }
- }
- catch (SQLException ex) {
- Logger.getLogger(FXMLRegistrationController.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- public void addUser(user newUser){
- userList.add(newUser);
- return;
- }
Add Comment
Please, Sign In to add comment