New to java and spring mvc. I am trying to print the database table in jsp view page. here is my logic 1. use array list to store the values of each column.(I have three columns in my table, So i am using three arraylist) 2. create three model and view objects
- iterate in jsp
I can only print one column in a table . I dont know how to combine all the three objects. Any help with the code will be appreciated.
listuser.java
RequestMapping(value = "/listuser.htm", method = RequestMethod.GET) public ModelAndView getdata() { System.out.println("Hello list users"); Connection conn=DatabaseConnection.getInstance(); List<String> id = new ArrayList<String>(); List<String> name = new ArrayList<String>(); List<String> password = new ArrayList<String>(); try { Statement st=conn.createStatement(); ResultSet rs=st.executeQuery("select * from login_details"); while(rs.next()) { // System.out.println(rs.getInt(1) +" " + rs.getString(2)+" " +rs.getString(3) ); id.add(rs.getString(1)); name.add(rs.getString(2)); password.add(rs.getString(3)); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } ModelAndView model = new ModelAndView("listuser"); model.addObject("lists", id); model.addObject("lists1",name); model.addObject("lists2",name); return model; }
if I want to print all the columns in the table in jsp, how do i write for each loop for three objects!!!!!!