How to display the data column on jsp

How to display the data column on jsp

My requirements: Display total error count of error description of each database server (column wise). like this:

Description DBServer1 DBServer2

Error1 10 22

Error2 20 30

Error3 66 32 ..

in table of each database having two columns: description, error. but data is dynamic. one database having 2 rows and another database could have 10 rows. so database should be mapped.(error with descrption)

program read a properties file where database server ip is defined and fill a array list with database server ip's. and using a loop over this database server ips to create db connection and all the tasks.

                HashMap hm=null;

                public HashMap getHm() {
                    return hm;
                }

                public void setHm(HashMap hm) {
                    this.hm = hm;
                }
                public  String countErrorData(){

                    //String[][] tempArray = null;
                    // ReadDBFile();
                     hm=new HashMap();
                     for (int j=0; j<dbSizeList.size();j++){
                             //mdList= new ArrayList();
                             //ArrayList errorCountList1= new ArrayList();
                             serverurl=String.valueOf(dbSizeList.get(j));
                            try {   
                                String connectionUrl=null;
                                 Class.forName("com.mysql.jdbc.Driver");

                                     connectionUrl = "jdbc:mysql://"+serverurl+":"+Global.myport+"/"+Global.database+"?" +
                                                           "user="+Global.myuser2+"&password="+Global.mypasswod+"&autoReconnect=true&useUnicode=true&characterEncoding=utf8";
                                    conn = DriverManager.getConnection(connectionUrl);
                                    stmt=conn.createStatement(); 

                    query="select distinct err as Description,count(error) as TotalErrors from tablename where err!='NA' GROUP by ERR ORDER BY TotalErrors desc";

                    System.out.println("error query:"+query);
                    try {
                         ArrayList errorList= new ArrayList();
                         rs=stmt.executeQuery(query);
                        rs.last();
                        row_count=rs.getRow();
                        rs.beforeFirst();
                        column_count=dbSizeList.size();
                        //tempArray = new String[row_count][column_count];

                         while (rs.next())
                         {
                            hm.put(rs.getString(1), rs.getString(2));
                            //errorCountList1.add(rs.getString(2));
                        }
                        dbURLList.add(serverurl);
                        /*for(int row=0; row < row_count; row++){
                            for (int i = z; i <= z; i++) {
                                tempArray[row][i] =(String)errorCountList1.get(row);
                                System.out.println("tempArray["+row+"]["+i+"]: "+tempArray[row][i]);
                                mdList.add(tempArray[row][i]);
                                }
                         }*/
                    }
                    catch(Exception e){

                        e.printStackTrace();
                    }
                            }catch(Exception e)
                            {
                                e.printStackTrace();
                            }

                        }
                        request.setAttribute("row_count", String.valueOf(row_count));
                        request.setAttribute("column_count", String.valueOf(column_count));
                        request.setAttribute("dbURLList", dbURLList); 
                        return "success";
                }

            jsp code:
                    <form id="myForm"   method="post">
                     <% 
                String column_count= (String)request.getAttribute("column_count");
                List dbURLList= (List)request.getAttribute("dbURLList"); 
                    %>
                <H2 align="center">Error Details</H2>
                <table  border="1" align="center">
                <tr><td>Description</td>
                <% for (int i = 0; i < Integer.parseInt(column_count); i++) { %>
                <td>  <%=dbURLList.get(i)%>  </td>
                <% }  %> 
                </tr>
                <c:forEach items="${hm}" var="entry">
                <tr><td>  ${entry.key}</td><td>  ${entry.value}</td></tr>
                </c:forEach>
                </table>
                </form>


            It display the data of last database server and it show in first column of database server column.
            suppose i have 2 database. it is showing like this:

            Description      localhost      localhost  
            Error1           138086
            Error2           1500
            Error3            99


            How i deal with this situtaion. should i set the data in a pojo and display the data in row wise. but database server ip is not fix. there may be 2 database or may be 5 database.
            Mapping (decription with error count of each database) on jsp is also a issue .
View Answers

June 9, 2017 at 10:12 PM

Hi,

In your code:

 while (rs.next())
              {
              hm.put(rs.getString(1), rs.getString(2));
              //errorCountList1.add(rs.getString(2));
              }

After getting data rs.getString(1) you can dispaly with the code out.println(rs.getString(1)) on jsp page.

Please check tutorial: Display Data from Database in JSP.

Thanks









Related Tutorials/Questions & Answers:
How to display the data column on jsp
How to display the data column on jsp  My requirements: Display total...; </form> It display the data of last database server... with this situtaion. should i set the data in a pojo and display the data in row wise
how to display data from database in jsp
how to display data from database in jsp  how to display data from database in jsp
Advertisements
how to display data in List Or grid or in table in Jsp
how to display data in List Or grid or in table in Jsp   <%@page...(); } %> </body> </html> this is my jsp code i want to display String P Value in List GIrd or Table please help am able to Print display data
how to display data from jsp file into database
how to display data from jsp file into database  this is a jsp file...+","+ph2+")"); out.println("Data is successfully inserted...+",'"+email+"')"); out.println("Data is successfully inserted into database
How to display data in jsp from dao using java beans?
How to display data in jsp from dao using java beans?  Hi I need to display data in jsp pulling from dao using java beans, Please can anyone give me the sample application with above topics. Any help would be highly appreciated
How to read and display data from a .properties file from a jsp page
How to read and display data from a .properties file from a jsp page ... the data from this .properties file and display it in table format. Ex:by using... = DEDCHGG_PWDP and goes on... I have to create a jsp page to show these data
Display Sum of Table Column Using In JSP
Display Sum of Table Column Using In JSP... an application to Display the sum data of a Table column for a specific Date. We... the total salary between two specific date and result is display using Jsp
How to display date in JSP?
How to display date in JSP?  How to create a simple JSP program which displays date on the page? Thanks
how to display data from mysql table in text box using jsp??
how to display data from mysql table in text box using jsp??  <p>hi, i have a written a code to display data from a mysql table into txtboxes... at line: 113 in the jsp file: /Cat1.jsp The local variable v_RGPC may not have
How to display date in JSP?
How to display date in JSP?  How to create a simple JSP program which displays date on the page? Thanks   Hi, You should import...() %> Check complete tutorial at How to Create JSP Page? Thanks
how to display output on jsp from while loop of action class....actually i am retreiving the post from posts column from my sql.plz help.thnkss
how to display output on jsp from while loop of action class....actually i am retreiving the post from posts column from my sql.plz help.thnkss  how to display output on jsp from while loop of action class....actually i am
Display Data from Database in JSP
; <html> <head> <title>display data from...;To display all the data from the table click here...</h2></TD>..., to show data from the database click on the link that calls another .jsp file named
data are not display in JSP from database - JSP-Servlet
data are not display in JSP from database   i want to finding some data through a SQL query from SQL server database to a JSP page based on some... of this jsp page. like.. School Result and three request parameters 'class', 'from
how to display the email message in jsp
how to display the email message in jsp  hi every one .. i am new from this industry please help me to display the email message in jsp page please send me sample code
How to display data fom MySQL DataBase-table in to JSP file by submitting a value in combobox.
How to display data fom MySQL DataBase-table in to JSP file by submitting a value in combobox.   I have the same problem.plz help me. I have MySQL... have to display the Nodename and packageno. i.e.,select nodename,packageno from
how to display data in excel sheet?
how to display data in excel sheet?  According to the user Id,some links will be generated from the database,and if we click a link,data would... the button and to display the data in excel sheet
How to Sort Column values of a jsp table - JSP-Servlet
How to Sort Column values of a jsp table  Hi Friend Please help me. I am displaying reultset values on multiple jsp page. I want to sort selected column values on every page onclick of an event its very urgent pleasehelp
unable to display table data on JSP page that is coming from mysql and servlet.
unable to display table data on JSP page that is coming from mysql and servlet.  I am unable to show table data on JSP page using servlet and mysql. only two rows data i showing but in my database I have five fields
unable to display table data on JSP page that is coming from mysql and servlet.
unable to display table data on JSP page that is coming from mysql and servlet.  I am unable to show table data on JSP page using servlet and mysql. only two rows data i showing but in my database I have five fields
unable to display table data on JSP page that is coming from mysql and servlet.
unable to display table data on JSP page that is coming from mysql and servlet.  I am unable to show table data on JSP page using servlet and mysql. only two rows data i showing but in my database I have five fields
How to Display Data in a tree structure on the GUI
How to Display Data in a tree structure on the GUI  how to display data in a tree structure on the GUI? I need this sort of UI to display data showing a set of rules showing various conditions and the actions related
How to display jfreechart at specified place in jsp
How to display jfreechart at specified place in jsp  I have a jsp page where i need to display the chart at specified position... of the jsp page is not displaying.... Below is my code. DefaultPieDataset
How to display multiple images in jsp
How to display multiple images in jsp  <%@ page import="java.io....()); System.out.println("st-7 "+brr); // display the image response.setContentType("image... "); } } catch (Exception e) { out.println("Unable To Display image"); out.println
How to copy existing column along with data and column name into another existing table
How to copy existing column along with data and column name into another existing table  i want to copy the existing column along with data... hyd xyz 678 how to do this.... i know that firstly the column
How to Display jrxml file on JSP page???
How to Display jrxml file on JSP page???  I made jrxml file using jasper report but how to display on jsp page?? i tried lot but still i didnt find out solution.so pls help me as soon as possible
jsp code for display of data from database and snap shot of the output
jsp code for display of data from database and snap shot of the output  i am using JSP.i want to insert data into database and also want to display... the following link: http://www.roseindia.net/jsp/displaydatafrom_database1.shtml
how to display one image on jsp through java
how to display one image on jsp through java  Hi, I wanted to display one image on my jsp file like social networking sites. But the scenario...://upload/image.jpg . what is the procedure to get that and display on my jsp page
How to add a column with checkboxes for each record in my table in JSP
How to add a column with checkboxes for each record in my table in JSP   Hi, Could you please explain it to me how I can add a column with check boxes for each record in my table in JSP? Also, I want to figure out a way
image display - JSP-Servlet
image display  how to display image that store in mysql database... column have BLOB datatype....  Hi Friend, Please visit the following link: http://www.roseindia.net/jsp/retrieve-image.shtml Thanks
how to display selected checkboxes dynamically using jsp
how to display selected checkboxes dynamically using jsp  Hi friends i have a requirement that : in my JSP page i have radio buttons followed by the DB fields..when i click SUBMIT button,if the field(or record
Dynamic retrieval od data from database and display it in the table at jsp
; Here is a jsp code that retrieves the data from the database and display...Dynamic retrieval od data from database and display it in the table at jsp  Hi friends.... Am creating software for chit fund.. I want to display
how display jsp frame - Java Beginners
how display jsp frame  Hi all, I am creating two jsp in frame... 1)In the code, you have provided,we have created another jsp 'new.jsp' in order to open the link on this jsp frame.It is having no code. Jsp Frameset
how to display the data from excel to webpage
how to display the data from excel to webpage  Hi, I need help... search for the value 4024 in a excel file and to display the remaining values on the same row. please help me out of this   Here is a jsp code
how to change a column data in a every row in a text file in java
how to change a column data in a every row in a text file in java   i have text file like this 11,6,13/9/14,1287605778,89... column in every row ie. account number to some text in a text file in java could
how to display each arraylist value on new page in jsp
how to display each arraylist value on new page in jsp  hi!!!! i want to display each arraylist value on new page in jsp????? and also want to access...://www.roseindia.net/jsp/servlet-jsp-data-list.shtml
how to display the excel file content in the jsp
how to display the excel file content in the jsp  How to present the content of the newly created excel file in the following jsp to the web browser: print("code sample"); <%@ page import="java.io.InputStream" %>
How to display images in jsp ffrom sqlserver2000 - JSP-Servlet
How to display images in jsp ffrom sqlserver2000   These code u sent is till not displaying the image in jsp from sqlserver2000. what table... for more information. http://www.roseindia.net/jsp/ Thanks
how to display or retrive an image in jsp whose path is stored in oracle database
how to display or retrive an image in jsp whose path is stored in oracle database  how to display or retrive an image in jsp whose path is stored in oracle database and the image is stored in my pictures folder
Display data
Display data  after successful login how i can fetch my account information from sql database
how to display action errors in jsp which is in a form list
how to display action errors in jsp which is in a form list  My jsp contains list of forms iterating using display:table, each FORM forms a row. I want to display action errors for individual form in the same row
How to display data from database in a TableView
How to display data from database in a TableView  I need to populate... at this. The classes: This is the Class that creates the database data object: import...; data; private List<NewBeautifulKiwi> initializeTable() { data
how to display values from database into table using jsp
how to display values from database into table using jsp  I want to display values from database into table based on condition in query, how... to display books based on either bookname or authorname, for this i created one jsp page
How to display image in jsp from database using Servlet?
How to display image in jsp from database using Servlet?  Hi, How to display image in jsp from database using Servlet? Thanks   Hi, You will find code and example program at Retrieve image from database using Servlet
Display Data from Database in JSP
Display Data from Database in JSP   ... and execute query to display data from the specified table.  Before.... This is first jsp page that has a link 'show data from table', user can show
how to display image and text in single jsp page from the mysql database
how to display image and text in single jsp page from the mysql database  hello please help me to display the image and text in single jsp page from mysql database if have any reference code please send me Thanks in advance
How to display data in form using aryylist in struts - Java Beginners
How to display data in form using aryylist in struts  Hi, I want to display data using arraylist in struts pls help me Its urgent
How to display Jfreechart from servlet in jsp web page at specified location
How to display Jfreechart from servlet in jsp web page at specified... to display the chart in web page. I generated the chart using Jfreechart in Servlet which is in image format.plz sir give me the code to display this chart
display of colors in a table - JSP-Servlet
display of colors in a table  Hi, If i have a table of 4 by 4 boxes, numbering from 1-16 in sequence, how do i make them display one column of one color and another column of another color? Thanks!  Hi Friend
how to display data into textboxes which is retrieved from the database
how to display data into textboxes which is retrieved from the database  I would like to know how to display data into textboxes which is retrieved from database in jsf. could you please provide a small example of how to do
how to display data into textboxes which is retrieved from the database
how to display data into textboxes which is retrieved from the database  I would like to know how to display data into textboxes which is retrieved from database in jsf. could you please provide a small example of how to do

Ads