aspose file tools*
The moose likes Beginning Java and the fly likes Printing records in two or more columns Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Printing records in two or more columns" Watch "Printing records in two or more columns" New topic
Author

Printing records in two or more columns

Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 740
there are 14 rows in a table in which I want to display a string record from db. The number of records are 50

I want that after 14 it goes and draw the next colum of the table despite printing in one column

Thanks & best regards
Gary Morris
Greenhorn

Joined: Apr 29, 2008
Posts: 8
Huh? You say there are 14 "rows" in a table, then go on to say there are 50 "records". Do you mean 14 FIELDS in each ROW (RECORD)? As far as I know, a row *IS* a record in most DB terminology!

Anyway, assuming you mean 14 table fields in each row/record, wouldn't it just be easier to go ahead and read all the fields in each one, then print the whole row on each line?
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 740
Originally posted by Gary Morris:
Huh? You say there are 14 "rows" in a table, then go on to say there are 50 "records". Do you mean 14 FIELDS in each ROW (RECORD)? As far as I know, a row *IS* a record in most DB terminology!

Anyway, assuming you mean 14 table fields in each row/record, wouldn't it just be easier to go ahead and read all the fields in each one, then print the whole row on each line?


I think I am unable to communicate my question in well form.

again say: I want to get records from db and to print into html <table> in two different columns but want to print in the way that each row should contain e.g. 5 records, means rows and then my program print 6th record in next column of the html table an so on e.g.

aa ff
bb gg
cc hh
dd ii
ee jj
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18880
    
    8

I think I have an idea of what your HTML should look like. But this is a Java in General forum so you are asking a question about Java, right? Then, what is your question about Java?
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 740
Originally posted by Paul Clapham:
I think I have an idea of what your HTML should look like. But this is a Java in General forum so you are asking a question about Java, right? Then, what is your question about Java?


Thanks for your reply
Sir, this is pure Java question as I am getting record from db with the help of Java Servlet and want to print them. Usually when we are printing records result set is printing in one column but I want to output the result set in the way that I mentioned above

Thanks again for your prompt reply
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18880
    
    8

So, you want some Java code to do that? Well, we don't do people's work for them here. Do you have some code for the easier version? We could start from that.
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 740
Originally posted by Paul Clapham:
So, you want some Java code to do that? Well, we don't do people's work for them here. Do you have some code for the easier version? We could start from that.


I am not asking to write the code or to do my work but just to get me some clue/ideas anyhow below is a simple code

Thanks for your replies

String query="select empno from emp";
PreparedStatement ps=cnn.prepareStatement(query);
rs=ps.executeQuery();
while(rs.next()){
int empno=rs.getInt(1);
out.println("<table><tr><td>"+empno+"</td><td>......");
//here it'll print in one column whereas I need to print as mentioned above
}
[ May 01, 2008: Message edited by: Farakh khan ]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18880
    
    8

Okay. So instead of generating one column you want to generate 5? Or was it 14? Anyway it doesn't matter, that's just a parameter.

Start a row by writing <tr>. Keep a counter and start writing columns <td>something</td>. When the counter reaches the parameter, end the row </tr> and start a new row. Reset the counter here.

You'll have to watch out for the case where the number of cells is an exact multiple of the number of columns, otherwise you'll end up with an empty row at the end. But don't worry about that for your first try. You can make it one of your test cases later.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Printing records in two or more columns