当我尝试从MySQL检索时间并将其设置为JLabel时,它会给我一个错误.
java.sql.sqlException: Illegal hour value ’50’ for java.sql.Time type
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); }
最佳答案我解决了这是代码,String 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;}
总结 以上是内存溢出为你收集整理的java.sql.SQLException:java.sql.Time的非法小时值’50’,值为’50:51:05全部内容,希望文章能够帮你解决java.sql.SQLException:java.sql.Time的非法小时值’50’,值为’50:51:05所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)