Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add column in resultset in java?

I have table employee

I retrieve the columns as select emp_name,emp_add from employee

while(iResultSet1.next())
            {
                List expRptColWise = new ArrayList();

                for(Integer i=1;i<=iResultSet1.getMetaData().getColumnCount();i++){


                        expRptColWise.add(iResultSet1.getString(i));

                }

                expRptRowWise.add(expRptColWise);

With the above snippet ,I get

emp_name | emp_add |
A        | add1    |
B        | add2    |

I want to add Serial No. coloumn in resultset so that I get result as

emp_name | emp_add |Sr_No|
A        | add1    |1    |
B        | add2    |2    |

Please guide me how to add column dynamically in resultset or collection object ,Here I have used ArrayList.

like image 923
Edward Avatar asked Nov 28 '25 06:11

Edward


1 Answers

use the following query

 select emp_name,emp_add, (ROW_NUMBER() OVER ( ORDER BY emp_name)) AS sr_no from employee
like image 67
Dinup Kandel Avatar answered Nov 30 '25 20:11

Dinup Kandel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!