0

1.I have a format required to be displayed in jsp. Where the rows should be displayed row wise.

2.These values(numbers) are dynamic i.e if the data is present in database i will get values else 0 will be got

3.The values are retrieved from database using ArrayList Concept

4.Data should be displayed in table format .

I have a format but not able to post it as image please let me know how can upload the format.

    AAAA    BBBBB   CCCCCC
A   3        4       0
B   43       3       2
C   0        3       3

    enter code here
    Connection con=null;
    Statement st= null;
    PreparedStatement pstmt=null;
     ResultSet x=null;
    String s1="";
    String age="";
    String s="";
    String tot="";
    %>

    
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con=DriverManager.getConnection("jdbc:odbc:sup_sup","scott","tiger");
    st=con.createStatement();
    x=st.executeQuery("SELECT name,COUNT(age)  ,COUNT(*) - COUNT(age) ,COUNT(*)  FROM supreeth_table GROUP BY name");

    %>
    

    ");
    out.println("NAME");
    while(x.next())
    {    
    out.println(""+x.getString(1)+"" );

    }
    out.println("");
    out.println("");
    out.println("NAMESS");
    while(x.next())
    {    
    out.println(""+x.getString(2)+"" );
    }
    out.println("");
    out.println("N");
    out.println("");
    out.println("A");
    out.println("");
    out.println("NA");
    %>
    
    
    
    

    

this is what the best could put up . Sorry with formatting I'm new to this

these data should be got from database in the same format. using arraylist,jsp.

Now i have tried to put the code i was trying pls help me out with answers Thank you in advance !!!

1 Answers1

3

Its not clear what you are saying here but I guess you are trying to get the output in a table format. Use table tags for it

<table>
<%
  while(x.next())
  {%>
  <tr>
   <td><%out.print(x.getString(1); %></td>
    <td><%out.print(x.getString(2); %></td>
    <td><%out.print(x.getString(3); %></td>
   </tr>
   <% 
   }
   %>

hope this would solve your formatting problem. For displaying images from your database you must fetch the image name from your data base where you fetch all other data. Say you add another field in your query as image. Now to display that image you must have that image in your project images folder. Following code would help you to get image.

<table>
<%
  while(x.next())
  {%>
  <tr>
   <td><img src="/images/<%out.print(x.getString(1)"; %></td>
Abinash Sinha
  • 840
  • 6
  • 18