我的表中有一列包含时间数据类型。我需要打印它的值(value)。这是我正在使用的代码:
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM student");
System.out.print("\t\t"+rs.getTime("Total Time"));
输出是 00:00:00,但我数据库中的实际值是 24:00:00。我怎样才能得到正确的值(value)?
最佳答案
调用rs.next()
在使用 getTime()
将光标向前移动到 first 行之前:
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM student");
if (rs.next()) {
System.out.print("\t\t"+rs.getTime("Total Time"));
}
来自文档:
A
ResultSet
cursor is initially positioned before the first row; the first call to the methodnext
makes the first row the current row; the second call makes the second row the current row, and so on.
关于java - 我如何从Java中的MySql获取时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12656486/