0

我一直在努力解决这个问题,我似乎无法找到解决办法。

public static void doQ(Connection c){
    try
    {
        stmt = c.createStatement();
        ResultSet rs1 = stmt.executeQuery("SELECT * FROM VQ1");
        ResultSet rs2 = stmt.executeQuery("SELECT * FROM VQ2");
        ResultSetMetaData meta = rs2.getMetaData();
        System.out.println(""); 
        System.out.println("Statistics for " + rs1.getString(2) + " By Spencer"); // This line recieves the error
        System.out.println("");
        System.out.println("Orders");
        System.out.println("============================================================ =========================");
        System.out.printf("%-10s %-10s %11s %12s\n", meta.getColumnName(1), meta.getColumnName(2), meta.getColumnName(3), meta.getColumnName(4));
        System.out.println("");
        while(rs2.next()){
            System.out.printf("%10s %10s %11s %12s\n",rs2.getString(1), rs2.getString(2), rs2.getString(3), rs2.getString(4));
        }//end while
        rs2.close();
        rs1.close();
    } catch (SQLException ex){
        System.err.println("\nERROR :" + ex.getMessage());

    }// end try catch

}//end method

每当我尝试运行我的代码时,都会收到一个用尽的 resultSet 错误。它应该打印出所有工作正常的列的完整表。我唯一遇到的问题是类似的

System.out.println("Statistics for " + rs1.getString(2) + " By Spencer");

我尝试将这行代码放入 if(rs1.next()) 但条件永远不会为真,所以它只是完全跳过了该行。我完全被难住了,希望得到一些帮助。

我的 Sql 视图

    DROP VIEW VQ1;

    CREATE VIEW VQ1
    AS
    SELECT COMPANYNAME, TO_CHAR(sysdate, 'dd/mm/yyyy') AS "date"
    FROM CUSTOMERS
    GROUP BY COMPANYNAME
    WITH READ ONLY;

    DROP VIEW VQ2;

    CREATE VIEW VQ2
    AS
    SELECT O.ORDERID, TO_CHAR(O.ORDERDATE, 'dd/mm/yyyy') AS "Order date",
    NVL2(O.SHIPPEDDATE, 'Shipped', 'Not Shipped') AS "Status",
    TO_CHAR(((OD.UNITPRICE * OD.QUANTITY) - (OD.UNITPRICE * OD.QUANTITY * OD.DISCOUNT)), '$999.99') AS "Total"
    FROM ORDERS O INNER JOIN ORDERDETAILS OD
    ON O.ORDERID = OD.ORDERID
    GROUP BY O.ORDERID, TO_CHAR(O.ORDERDATE, 'dd/mm/yyyy'), NVL2(O.SHIPPEDDATE,'Shipped', 'Not Shipped'), TO_CHAR(((OD.UNITPRICE * OD.QUANTITY) - (OD.UNITPRICE * OD.QUANTITY * OD.DISCOUNT)), '$999.99')
    WITH READ ONLY;
4

0 回答 0