1 6 7 package com.quikj.application.communicator.applications.webtalk.model; 8 9 import java.sql.*; 10 import java.util.*; 11 15 public class TrafficDataBean 16 { 17 18 private java.sql.Date startDate; 19 20 private java.sql.Date endDate; 21 22 private String groupid; 23 24 private ArrayList result; 25 26 27 private int height; 28 29 30 private int width; 31 32 public TrafficDataBean() 33 { 34 } 35 36 public static java.sql.Date convertDate(String date) 37 { 38 StringTokenizer tokens = new StringTokenizer(date, "/"); 39 if (tokens.countTokens() != 3) 40 { 41 return null; 42 } 43 44 int m = 0; 45 int d = 0; 46 int y = 0; 47 48 try 49 { 50 m = Integer.parseInt(tokens.nextToken()) - 1; 51 d = Integer.parseInt(tokens.nextToken()); 52 y = Integer.parseInt(tokens.nextToken()); 53 54 Calendar cal = Calendar.getInstance(); 55 cal.setLenient(false); 56 57 try 58 { 59 cal.set(y, m, d, 0, 0, 0); 60 } 61 catch (Exception ex) 62 { 63 return null; 64 } 65 66 return new java.sql.Date (cal.getTime().getTime()); 67 } 68 catch (NumberFormatException ex) 69 { 70 return null; 71 } 72 } 73 74 78 public String getGroupid() 79 { 80 return groupid; 81 } 82 83 87 public void setGroupid(String groupid) 88 { 89 this.groupid = groupid; 90 } 91 92 96 public java.sql.Date getEndDate() 97 { 98 return endDate; 99 } 100 101 105 public void setEndDate(java.sql.Date endDate) 106 { 107 this.endDate = endDate; 108 } 109 110 114 public java.sql.Date getStartDate() 115 { 116 return startDate; 117 } 118 119 123 public void setStartDate(java.sql.Date startDate) 124 { 125 this.startDate = startDate; 126 } 127 128 public void setResult(ArrayList result) 129 { 130 this.result = result; 131 } 132 133 public ArrayList getResult() 134 { 135 return result; 136 } 137 138 public void searchDatabase(Connection c) 139 { 140 try 141 { 142 List temp_list1 = new ArrayList(); 143 List temp_list2 = new ArrayList(); 144 List temp_list3 = new ArrayList(); 145 List temp_list4 = new ArrayList(); 146 147 String select = "Select time_stamp, opm_name, opm_value from opm_operator_tbl where groupid = ?" 148 + " AND (time_stamp BETWEEN ? AND ?)" 149 + " AND ((opm_name='users_waiting') or (opm_name='users_talking') or (opm_name='actv_ops'))" 150 + " order by time_stamp"; 151 152 Statement st = c.createStatement(); 153 st.execute("use webtalk ;"); 154 155 PreparedStatement ps = c.prepareStatement(select); 156 ps.setString(1, getGroupid()); 157 ps.setDate(2, getStartDate()); 158 ps.setDate(3, getEndDate()); 159 ResultSet rs = ps.executeQuery(); 160 161 if (rs == null) 162 { 163 result = null; 164 } 165 else 166 { 167 Timestamp last = new Timestamp(0L); 168 while (rs.next()) 169 { 170 Timestamp ts = rs.getTimestamp(1); 171 String opm_name = rs.getString(2); 172 int count = rs.getInt(3); 173 174 if (ts.equals(last) == false) 175 { 176 temp_list1.add(ts); 177 last = ts; 178 } 179 180 if (opm_name.equals("actv_ops") == true) 181 { 182 temp_list2.add(new Integer (count)); 183 } 184 else if (opm_name.equals("users_waiting") == true) 185 { 186 temp_list3.add(new Integer (count)); 187 } 188 else if (opm_name.equals("users_talking") == true) 189 { 190 temp_list4.add(new Integer (count)); 191 } 192 } 193 194 result = new ArrayList(); 195 result.add(temp_list1); 196 result.add(temp_list2); 197 result.add(temp_list3); 198 result.add(temp_list4); 199 rs.close(); 200 } 201 } 202 catch (Exception e) 203 { 204 } 206 } 207 208 212 public int getHeight() 213 { 214 return this.height; 215 } 216 217 221 public void setHeight(int height) 222 { 223 this.height = height; 224 } 225 226 230 public int getWidth() 231 { 232 return this.width; 233 } 234 235 239 public void setWidth(int width) 240 { 241 this.width = width; 242 } 243 244 } | Popular Tags |