refactoring
This commit is contained in:
parent
a832375223
commit
e5a3fafa09
@ -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();
|
||||
|
@ -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<User> findAll(){
|
||||
ArrayList<User> users = new ArrayList<User>();
|
||||
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<User> findByName(String name){
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean insertUser(User User){
|
||||
return false;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user