@H_301_1@当我尝试从MySQL检索时间并将其设置为JLabel时,它会给我一个错误.
@H_301_1@
@H_301_1@java.sql.sqlException: Illegal hour value ’50’ for java.sql.Time type@H_301_1@任何人都可以建议我如何解决这个问题? @H_301_1@代码如下. @H_301_1@
in value ’50:51:05.
String sql = "SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(ot)))"
+ " FROM attendance"
+ " WHERE department = '"+department+"'"
+ " AND date BETWEEN '"+dateChooser1+"' AND '"+dateChooser2+"'";
st = con.createStatement();
rst = st.executeQuery(sql);
if(rst.next())
{
String time = rst.getString(1);
oTimeTemp.setText(time);
}
最佳答案
我解决了这是代码,
@H_301_1@
原文链接:https://www.f2er.com/mysql/432895.htmlString sql = "SELECT SUM(TIME_TO_SEC(ot))"
+ " FROM attendance"
+ " WHERE department = '"+department+"'"
+ " AND date BETWEEN '"+dateChooser1+"' AND '"+dateChooser2+"'";
st = con.createStatement();
rst = st.executeQuery(sql);
if(rst.next())
{
String time = rst.getString(1);
Double dTime = Double.valueOf(time);
int intTime = (int) dTime.doubleValue();
String nTime = calculateTime(intTime);
oTimeTemp.setText(nTime);
}
private static String calculateTime(int totalSecs)
{
int hours = totalSecs / 3600;
int minutes = (totalSecs % 3600) / 60;
int seconds = totalSecs % 60;
String timeString = String.format("%02d:%02d:%02d",hours,minutes,seconds);
return timeString;
}