diff --git a/src/main/java/HourTracker.java b/src/main/java/HourTracker.java index a887a63..5ba83f6 100644 --- a/src/main/java/HourTracker.java +++ b/src/main/java/HourTracker.java @@ -1,11 +1,5 @@ import db.DBConnection; -/* - * This Java source file was auto generated by running 'gradle buildInit --type java-library' - * by 'tyrelsouza' at '2/27/17 9:23 PM' with Gradle 2.10 - * - * @author tyrelsouza, @date 2/27/17 9:23 PM - */ public class HourTracker { public void main(String[] args){ DBConnection db = new DBConnection(); diff --git a/src/main/java/dao/UserDAO.java b/src/main/java/dao/UserDAO.java index ae47bee..686bace 100644 --- a/src/main/java/dao/UserDAO.java +++ b/src/main/java/dao/UserDAO.java @@ -23,19 +23,27 @@ public class UserDAO { public UserDAO() { db = new DBConnection(); } + private User getUserFromResultSet(ResultSet rs){ + try { + Integer userid = Integer.parseInt(rs.getString("id")); + String username = rs.getString("username"); + String fullName = rs.getString("full_name"); + User user = new User(userid, username, fullName); + return user; + } catch (SQLException e) { + return null; + } + } public ArrayList findAll(){ ArrayList users = new ArrayList(); PreparedStatement ps; try { - ps = db.connection.prepareStatement("SELECT id, username, full_name FROM user"); + ps = db.connection.prepareStatement( + "SELECT id, username, full_name FROM user"); ResultSet rs = ps.executeQuery(); while (rs.next()) { - Integer userid = Integer.parseInt(rs.getString("id")); - String username = rs.getString("username"); - String fullName = rs.getString("full_name"); - User user = new User(userid, username, fullName); - users.add(user); + users.add(getUserFromResultSet(rs)); } return users; } catch (SQLException e) { @@ -51,19 +59,14 @@ public class UserDAO { ps.setInt(1, id); ResultSet rs = ps.executeQuery(); rs.next(); - Integer userid = Integer.parseInt(rs.getString("id")); - String username = rs.getString("username"); - String fullName = rs.getString("full_name"); - User user = new User(userid, username, fullName); - return user; + + return getUserFromResultSet(rs); } catch (SQLException e) { e.printStackTrace(); } return null; } - public List findByName(String name){ - return null; - } + public boolean insertUser(User User){ return false; } diff --git a/src/main/java/db/DBConnection.java b/src/main/java/db/DBConnection.java index 806176e..da865ea 100644 --- a/src/main/java/db/DBConnection.java +++ b/src/main/java/db/DBConnection.java @@ -4,9 +4,6 @@ import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; -/** - * Created by tyrelsouza on 2/27/17. - */ public class DBConnection { public static Connection connection = null;