I'm not doing very well with what I'm trying to do at the moment. The aim is to to get all information from a MySQL table and put it into an array. Once into an array I will use the priority queue in java and try to get it to work with that.... but that's not the issue I'm stuck on at the moment.
public static void array(String args[]) { // create priority queue
try {
String url = "jdbc:mysql://localhost:3306/project";
Connection conn = DriverManager.getConnection(url,"root","nbuser");
PreparedStatement stmt = conn.prepareStatement("SELECT user_id,s_date,e_date,d_date,department,projectname,projectapplication FROM booking");
ResultSet rs;
rs=stmt.executeQuery();
List<User> userList = new ArrayList<User>();
while(rs.next()) {
User user = new User(); //issue here with non-static variable
user.userid(rs.getString("user_id"));
user.s_date(rs.getObject("s_date"));
user.e_date(rs.getObject("e_date"));
user.d_date(rs.getObject("d_date"));
user.department(rs.getObject("department"));
user.projectname(rs.getObject("projectname"));
user.projectapplication(rs.getObject("projectapplication"));
user.priority(rs.getObject("priority"));
userList.add(user);
}
conn.close();
} catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
The aim is to get it to run through all the different sections in the table and populate them into an array, but I'm stuck on populating the array.
Any help would be appreciated thanks.
EDIT:
public class User {
public String userid;
public String s_date;
public String e_date;
public String d_date;
public String department;
public String projectname;
public String projectapplication;
public int priority;
private void userid(String string) {
throw new UnsupportedOperationException("Not yet implemented");
}
private void s_date(Object object) {
throw new UnsupportedOperationException("Not yet implemented");
}
private void e_date(Object object) {
throw new UnsupportedOperationException("Not yet implemented");
}
private void d_date(Object object) {
throw new UnsupportedOperationException("Not yet implemented");
}
private void department(Object object) {
throw new UnsupportedOperationException("Not yet implemented");
}
private void projectname(Object object) {
throw new UnsupportedOperationException("Not yet implemented");
}
private void projectapplication(Object object) {
throw new UnsupportedOperationException("Not yet implemented");
}
private void priority(Object object) {
throw new UnsupportedOperationException("Not yet implemented");
}
}
similar to this?