以下代码找不到任何数据。因此res.next()不返回任何内容。如果我在SQL Developer工具中尝试相同的查询,它将返回1行。 Java代码有什么问题?这是该死的简单代码,但是由于某些原因它不起作用。请告诉我。
我的表为:-
CREATE TABLE MYTASK
(
"MARKET" VARCHAR2(3 CHAR) NOT NULL ENABLE,
"ENV" NUMBER(4,0) NOT NULL ENABLE,
"NR" NUMBER(4,0) NOT NULL ENABLE,
"ADD_DATE" DATE,
"USERNAME" VARCHAR2(50 CHAR),
"INFO" VARCHAR2(2000 CHAR),
"RUN_DATE" DATE DEFAULT sysdate
);
现有数据:-
Java代码:-
private static final String READ_MY_TASK = "select M.MARKET, M.USERNAME, M.INFO" + " from MYTASK M where M.ENV = ?"
+ " and M.NR = ? and M.RUN_DATE <= sysdate" + " group by M.MARKET, M.USERNAME, M.INFO" + " order by MIN(M.RUN_DATE) asc";
public static void main(String[] args) throws Exception {
readMytask(5, 20);
}
public static void readMytask(int cmd, int number) throws Exception {
PreparedStatement pst = null;
ResultSet res = null;
Connection connection = null;
try {
connection = DriverManager.getConnection(url, user, pass);
pst = connection.prepareStatement(READ_MY_TASK);
pst.setInt(1, cmd);
pst.setInt(2, number);
// This call retrun no data. Alghoh I have few rows.
res = pst.executeQuery();
while (res.next()) {
System.out.println(res.getString("MARKET"));
System.out.println(res.getString("USERNAME"));
System.out.println(res.getString("MARKET"));
}
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
res.close();
pst.close();
connection.close();
}
}
所有三个条目的NR = 20,但是您选择了NR = 10的条目,因此没有结果。