KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > mysql > Destination


1 package net.sf.jasperreports.mysql;
2
3 import java.sql.SQLException JavaDoc;
4 import java.sql.Statement JavaDoc;
5
6 /**
7  * Extends Database to include methods to check for the
8  * apropriate tables and create them if necissary.
9  */

10 public class Destination extends Database
11 {
12
13     /**
14      * creates the necisarry tables if they do not already exist.
15      * tables: status, process_list, and table_status.
16      */

17     public void createTables()
18     {
19         //System.out.print("trying to create the tables...\n");
20
createShowStatus();
21         createProcessList();
22         createTableStatus();
23
24     }
25
26     /**
27      * Creates the table status table with columns:
28      * <p/>
29      * source VARCHAR(255)
30      * report_time TIMESTAMP
31      * bytes_received BIGINT
32      * bytes_sent BIGINT
33      * total_selects BIGINT
34      * total_insert BIGINT
35      * connections BIGINT
36      * uptime BIGINT
37      */

38
39     private void createShowStatus(){
40            //System.out.print("\tcreating table status...");
41
try{
42             //creae the table status
43
Statement JavaDoc create = getConnection().createStatement();
44             create.executeUpdate("CREATE TABLE IF NOT EXISTS status(" +
45                                     "source VARCHAR(255)," +
46                                     "report_time TIMESTAMP(12)," +
47                                     "bytes_received BIGINT," +
48                                 "bytes_sent BIGINT," +
49                                 "total_selects BIGINT," +
50                                 "total_insert BIGINT," +
51                                 "connections BIGINT," +
52                                     "uptime BIGINT" +
53                                 ");"
54                             );
55            }catch(SQLException JavaDoc e){
56             e.printStackTrace();
57             System.out.println("Exception: " + e.getMessage());
58             System.exit(1);
59            }
60            System.out.print("created table: status.\n");
61         }
62     
63
64     /**
65      * Creates the table process_list with columns:
66      * <p/>
67      * source VARCHAR(255)
68      * report_time TIMESTAMP
69      * user VARCHAR(255)
70      * host VARCHAR(255)
71      * database_name VARCHAR(255)
72      * time BIGINT
73      *
74      */

75
76     private void createProcessList(){
77        //System.out.print("\tcreating table process_list...");
78
try{
79         //ceate the table process list
80
Statement JavaDoc create = getConnection().createStatement();
81         create.executeUpdate("CREATE TABLE IF NOT EXISTS process_list(" +
82                                 "source VARCHAR(255)," +
83                                 "report_time TIMESTAMP(12)," +
84                                 "user VARCHAR(255)," +
85                                 "host VARCHAR(255)," +
86                                 "database_name VARCHAR(255)," +
87                                 "time BIGINT" +
88                              ");"
89                             );
90        }catch(SQLException JavaDoc e){
91         e.printStackTrace();
92         System.out.println("Exception: " + e.getMessage());
93         System.exit(1);
94        }
95        System.out.print("created table: process_list.\n");
96     }
97
98     /**
99      * Creates table status with columns:
100      * <p/>
101      * source VARCHAR(255)
102      * database VARCHAR(255)
103      * report_time TIMESTAMP
104      * name VARCHAR(255)
105      * create_time DATETIME
106      * rows BIGINT
107      * average_row_length BIGINT
108      * data_length BIGINT
109      * index_length BIGINT
110      * update_time DATETIME
111      * check_time DATETIME
112      */

113     
114     private void createTableStatus(){
115            //System.out.print("\tcreating table table_status...");
116
try{
117             //create the table table status
118
Statement JavaDoc create = getConnection().createStatement();
119             create.executeUpdate("CREATE TABLE IF NOT EXISTS table_status(" +
120                                     "source VARCHAR(255)," +
121                                 "database_name VARCHAR(255)," +
122                                     "report_time TIMESTAMP(12)," +
123                                     "name VARCHAR(255)," +
124                                 "create_time DATETIME," +
125                                     "rows BIGINT," +
126                                 "average_row_length BIGINT," +
127                                 "data_length BIGINT," +
128                                 "index_length BIGINT," +
129                                 "update_time DATETIME," +
130                                 "check_time DATETIME" +
131                              ");"
132                             );
133            }catch(SQLException JavaDoc e){
134             e.printStackTrace();
135             System.err.println("Exception: " + e.getMessage());
136             System.exit(1);
137        }
138            System.out.print("created table: table_status.\n");
139     }
140 }
141
Popular Tags