Output statistical statistics on the web page with Java

zhaozj2021-02-11  245

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 MaxValue) maxValue = value [i];} xmargin = maxlen 10; // ymargin = fontmetrics.getHeight () 10; int Cheight = fontmetrics.getHEight (); int adjust = getStep (maxValue); // calculate X coordinate scale unit scale = (width-xmargin) / maxValue; eHight = (Height-ymargin) / row; g.drawRect (xmargin-1, 0, width-xmargin, height -ymargin); // Painted graphics FOR (int i = 1; i * step10) {mO = mo * 10; ST = (int) (value / 10) / mo;} Return (ST 1) * mo;}} The query of the database is implemented in the CreatResultset method in the Applet primary class: Private Static ResultSet CreatResultSet (String DSTR, STRING SQLSTR) / * Read Database * / {...} based on a given data source and SQL query statement In the Paint () method of the Applet primary class, the DRAW method of the class GraphPost can realize the output of the chart. In order to save the query results in the data buffer in the graphpost, you need to use multiple times multiple times, you need to define a GraphPost object as a member of the Applet primary class. In the init () method of the Applet primary class, the GraphPost object is initialized and the JDBC driver registration is completed. In the Start () method of the Applet primary class, connect the database, execute the query, and store the query results into the data buffer of the GraphPost object. In this way, when you return to the page containing the applet, you must re-query the database to ensure the latest information on the database.

转载请注明原文地址:https://www.9cbs.com/read-3548.html

New Post(0)