从查询中,我不知道如何检索java的resultset中的值。我想为用户显示考勤报告。
BEGIN
SET SESSION group_concat_max_len = 1000000000;
SET @sql = NULL ;
SELECT
GROUP_CONCAT(
DISTINCT CONCAT(
'max(CASE WHEN attendance.date = '',
DATE_FORMAT(DATE, '%Y-%m-%d'),
'' THEN coalesce(p.present, '') END) AS `',
DATE_FORMAT(DATE, '%Y-%m-%d'),
'`'
)
) INTO @sql
FROM
calendar
WHERE DATE >= '2015-01-01'
AND DATE <= '2015-01-31' ;
SET @sql = CONCAT(
'SELECT attendance.present,attendance.user_id, ', @sql,'
from
(
select c.date, a.user_id,a.present
from calendar c
cross join attendance a
) attendance
left join attendance p
on attendance.user_id= p.user_id
and attendance.date = p.attendance_date
where attendance.date>='2015-01-01'
and attendance.date <= '2015-01-31'
group by attendance.user_id'
) ;
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END
这个过程是在java代码中调用的,现在我想检索结果的值以显示给用户
String sp_query = "CALL AttendanceTrying()";
try {
connection = DBUtil.getInstance().getConnection();
callableStatement = connection.prepareStatement(sp_query);
resultSet = callableStatement.executeQuery();
while(resultSet.next()) {
Attendance attendance = new Attendance();
/*here I don't know how to retrieve the values of procedure*/
}
调用resultset.getXXX()方法的相应输出。ie)您需要int、string、sting这三行数据,然后通过resultset调用结果集。getInt(1)->给出整数值,resultset。getString(2)-->给出字符串值,resultset,getString(3)-->给出串值。