0

String sql = "SELECT ID, NAME, SALARY FROM EMPLOYEE";
  
public List<Employee> getAllEmployees(Connection con){
  
    List<Employee> elist = new ArrayList();
          
    try{
        //prepared statement 
        //
        //
    }catch(){
        //exception
    }
  
    return elist;
  
}

Guys, I have a java class which selects List of values from DB. So far my code is running good I did debugging and I can see my query in eclipse console. Now I need to display java returned value(LIST) with different data types in jsp page. I am stuckI somehow I need to loop javaclass return value or something and display in jsp page. Please help me I have spent 2 hrs and can't come up with anything. i am uisng struts 2.0 and Employee class contains setter/getter

Mahesh Mishra
  • 39
  • 1
  • 6
  • 1
    The values need to be added to the `request` or `session` before calling the JSP. You are not showing enough information - how/where are you calling the JSP? – Scary Wombat Sep 05 '18 at 04:44
  • Please format the code so it is easy to read. Also add the minimum code to give a context. How it is now there is nothing relating it to an EE application. Is it a method of a Servlet, are you using a framework like Spring or Struts? – Juan Sep 05 '18 at 04:44
  • 1
    You should add your List of values to the request or session object and then access your data from JSP. You can use JSTL for simple looping/iterating through your items. – adn.911 Sep 05 '18 at 04:46
  • Have a look at the follwoing Q&A: [How to display a list in a .JSP file?](https://stackoverflow.com/questions/18085476/how-to-display-a-list-in-a-jsp-file) The question reads like yours. Didn't you searched for ?? – LuCio Sep 05 '18 at 07:14
  • thx guys for great help, I was able to figure out. – Mahesh Mishra Sep 05 '18 at 13:39

1 Answers1

0
String sql = "select ID, NAME, SALARY FROM EMPLOYEE";
PreparedStatement ps = con.prepareStatement(sql);

ResultSet rs = ps.executeQuery();

you have to store all the data into ResultSet. Than you have to create Arraylist.

List<Integer> values = new ArrayList<>();
values.add(index,rs.next());
values.add(index1,rs.next());

//This is way to your code. not complete code of yours.