我目前做的事情做得不是很好。目的是从 MySQL 表中获取所有信息并将其放入数组中。一旦进入一个数组,我将使用 java 中的优先级队列并尝试让它与它一起工作......但这不是我目前遇到的问题。
public static void array(String args[]) { // 创建优先队列
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());
}
}
目的是让它遍历表中的所有不同部分并将它们填充到一个数组中,但我坚持填充数组。
任何帮助将不胜感激。
编辑:
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");
}
}
类似于这个?