Output statistics on the web page with Java
Henan Jiaozuo Water Conservancy Bureau Nie Chunsheng
In Internet and intranet applications, the combination of databases and web technology is the key to the traditional MIS system transplantation to the Internet (Intrant) environment. Many manufacturers have launched their own products, but these products are basically the HTML format for implementing data. Output. In practical applications, we often need to exhibit data in a statistical form, such as the output of the stock market graph. The traditional method is to put the chart as a graphic file into the web server's directory. Although this approach is simple, there is a significant limitations: First, the graphic file should take up large storage space; the other is difficult to adapt to the flexible and complex query requirements; the graphics file is updated with the database change, and the server's burden is increased. It is also easy to cause inconsistencies in graphics and databases. Obviously, to achieve the above requirements, two key links are required: one is to read data from the database; second, draw in the web page based on the read data. We use JDBC access to the database, drawing in the web page, using the Graphics class implemented in the java.awt package. To facilitate expression, the establishment of the data sheet is as follows:
Objective water production reagent 60 engineering management 89 anti-drought flood flood 100 financial 200 office public room 350 survey design 80
Our goal is to show the top table with a chart (this paper). The database referred to herein is a table of forms in the above form. The field 1 is a character field, indicating item information; field 2 is a numeric field (read with floating point), indicating the number of indicators. In practical applications, the program is slightly modified to make it more flexible. To draw various forms of charts, first define a graph abstraction class (note not graphics): import java.sql. *; Import java.awt. *; Abstract Class graph {int Height, width; // Drawing area High and Wide int maxRow = 50, row = 0; // can accommodate the maximum record number and the number of records color color = new color (50, 50, 200); // Default draw color float scale; // scale string [] name; // Project Name Buffer Float [] Value; // Indicator Value PUBLIC GRAPH (Dimension D, Int MaxRows, Color Fcolor) {Height = D.Height; width = D.Width; Name = New String [maxRows]; Value = new float [maxROWS]; color = fcolor;} public void setResult (resultset result) {// Put the query result in buffer try {row = 0; while (result.next () && rot Import java.sql. *; import java.awt. *; public class graphpost extends graph {float interval = 0; // Cylindrical blank proportion in the column width (including the plumbing blank) 0