在一个mysql存储过程中,怎么处理select语句返回的一个结果集
如下面这条语句
select r.problem_no, max(answer_time) from real_time
执行之后,我希望接下来对每一行结果进行判断,然后进行处理。
如下面这条语句
select r.problem_no, max(answer_time) from real_time
执行之后,我希望接下来对每一行结果进行判断,然后进行处理。
} public User getUser(String username, String password) throws NamingException, SQLException {
DataSource ds = null;
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
User user = null; try {
Context ctx = new InitialContext();
if (ctx == null) {
throw new RuntimeException("鎵句笉鍒癑NDI!");
}
ds = (DataSource) ctx.lookup("jdbc/exam");
if (ds == null) {
throw new RuntimeException("鎵句笉鍒癉ataSource!");
}
conn = ds.getConnection();
ps = conn.prepareStatement(GET_USER);//得到语句集通道
ps.setString(1, username);// 设语句参数
ps.setString(2, password);
rs = ps.executeQuery();//执行语句
//从语句集里得到想要的信息
while (rs.next()) {
int ObjectId = rs.getInt("uid");
user = new User(ObjectId, rs.getString("username"), rs.getString("password"));
}
return user; } catch (SQLException se) {
throw new RuntimeException("A database error occured. " + se.getMessage());
} catch (NamingException ne) {
throw new RuntimeException("A JNDI error occured. " + ne.getMessage());
} finally {//鍏虫祦
if (rs != null) {
try {
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if (ps != null) {
try {
ps.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
但是LZ的SQL语句好像有问题