Istvan
Istvan

Reputation: 73

Java resultset displayed in reverse order

I'm testing a very simple Java webapp doGet() method with the following code:

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
{
    try 
    {
        Class.forName("oracle.jdbc.OracleDriver");
    }
    catch(ClassNotFoundException ex)
    {
            System.out.println(ex);
    }

    String sql_qrp="select * from HR.EMP_MGMT";

    try
    {
        Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/XE","HR","HR");

        try(Statement stm=con.createStatement())
        {
            ResultSet rs=stm.executeQuery(sql_qrp);

            while(rs.next())
            {
                int emp_ID=rs.getInt("EMP_ID");
                String name=rs.getString("NAME");
                String address=rs.getString("ADDRESS");
                int tel=rs.getInt("TEL");
                String email=rs.getString("EMAIL");

                System.out.println(emp_ID+", "+name+", "+address+", "+tel+", "+email);
            }
        }
    }
    catch (SQLException ex) {
        Logger.getLogger(Add_Employee.class.getName()).log(Level.SEVERE, null, ex);
    }
}

It connects well to Oracle db and fetches all 3 rows from the table specified in the code, BUT IN REVERSE ORDER. I already tried to force FETCH_FORWARD with no success. So it fetched records like: ID 3.,2.,1. and not ID 1., 2., 3.

Upvotes: 0

Views: 1535

Answers (1)

user1907906
user1907906

Reputation:

Add

ORDER BY id ASC

to sql_qrp.

Upvotes: 1

Related Questions