Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-26-2008, 10:07 PM
Member
 
Join Date: May 2008
Posts: 1
davwhite is on a distinguished road
Formatting resultset for html
Hi, I have been working on an application which produces html pages and excel spreadsheets from queries from a relational database. I am new to Java and am not aware of all the tools and tricks to optimize the code, so I have constructed a very simple formatter to wrap the results of the resultset in HTML tags. The code works but gets very slow when lots of columns are selected. Here are the basics:

1. The data stored in the database uses 4 tables. Regions, Countries, Clients, and Indicators. Indicators holds all the detail data for each client by quarter.
2. The requirement for the reports is that each row contain individual client information and a column for each quarter for the same client.
Ex.
|Country1|Sector1|Client1Name|Client1Info|Client1Q 1Y1data|Client1Q2Y1data|Client1Q3Y1data|Client1Q4Y 1data
|Country1|Sector1|Client2Name|Client2Info|Client2Q 1Y1data|Client2Q2Y1data|Client2Q3Y1data|Client2Q4Y 1data
|Country1|Sector1|TOTALS| Q1Y1TOTAL | Q2Y1TOTALS | Q3Y1TOTALS | Q4Y1TOTALS
|Country1|Sector2|Client3Name|Client3Info|Client3Q 1Y1data|Client3Q2Y1data|Client3Q3Y1data|Client3Q4Y 1data
|Country1|Sector2|TOTALS| Q1Y1TOTAL | Q2Y1TOTALS | Q3Y1TOTALS | Q4Y1TOTALS
|Country1|TOTALS| Q1Y1TOTAL | Q2Y1TOTALS | Q3Y1TOTALS | Q4Y1TOTALS

3. The user has the option of turning columns on or off for the report.

Using MySQL temporary tables and dynamic query generation from my java code I have managed to create the pivot table which looks exactly like the output I want. The problem is that when all quarters (4 quarters per year for three years) are selected with all indicators (9 indicators per client) for all clients (334 for now) it takes more than 10 minutes to return the page. I have determined that the creation of the temp tables and joins takes less than 5 seconds. The part that takes the longest time is formatting the recordset output with HTML tags.

So my question is this. Are there libraries which can quickly do the formatting for a resultset? Or is there something really stupid I'm doing in my code which is slowing things down? Below is the code and information on my environment.

JDK: 1.6
Server: Apache Tomcat 6.0
Database: MySQL 5.1.18
Platform: Windows (development) Linux (production)

====================Formatting Code ======================

s_Query6 = "select * from temp_pivot5 order by country,sector,client_name,rowtype";
rResults = stmt.executeQuery(s_Query6);
while (rResults.next()) {

boolean BoldTag = false;
String ThisRowType = rResults.getString("rowtype");
if (ThisRowType.equals("0")) {
ResultTable += RowStart;
}
if (ThisRowType.equals("1")) {
ResultTable += SectorTotalRowStart;
BoldTag = true;
}
if (ThisRowType.equals("2")) {
ResultTable += CountryTotalRowStart;
BoldTag = true;
}
for (int a = 0; a < ColCount; a++) {
String ThisIndex = (String) ActiveIndexes.elementAt(a);
if (ThisIndex.equals("1")) {

String ThisRow = " ";
if (rResults.getString(a + 1) != null) {
if (ColTypes.elementAt(a).equals("num")) {
ThisRow = (String) notmoney.format(rResults.getInt(a + 1));
}
if (ColTypes.elementAt(a).equals("perc")) {
ThisRow = (String) notmoney.format(rResults.getInt(a + 1));
ThisRow += "%";
}
if (ColTypes.elementAt(a).equals("text")) {
ThisRow = rResults.getString(a + 1);
}
}
if (BoldTag) {
ResultTable += ColumnStart + BoldTagStart + ThisRow + BoldTagEnd + ColumnEnd;
} else {
ResultTable += ColumnStart + ThisRow + ColumnEnd;
}
}
}

ResultTable += RowEnd;
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ResultSet to HTML Java Tip Java Tips 0 02-12-2008 11:32 AM
Showing ResultSet in HTML table Java Tip Java Tips 0 01-27-2008 10:09 PM
formatting.. sireesha New To Java 10 01-07-2008 09:51 AM
formatting String bugger New To Java 1 11-16-2007 09:27 PM
Formatting the date yuchuang New To Java 5 05-07-2007 08:08 PM


All times are GMT +3. The time now is 05:48 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org