// private string node; public SingleNodeTrafficInputs(TaskElement task) { this.task = task; if (task.getDataSource().equals("DataBase")) { conn = new OracleUtils(); if (!conn.tryConnect()) System.out.println("数据库无法连接!"); // UtilsUI.showErrMsg("锟斤拷菘锟斤拷薹锟斤拷锟斤拷樱锟�); } }
@Override public DataItems readInputBySql(String condition) { String sqlStr = condition; // sql语句需要根据实际情况的表进行书写 String whichNode = condition; DataItems dataItems = new DataItems(); Calendar lastYear = Calendar.getInstance(); lastYear.set(2014, 9, 1, 0, 0, 0); conn.closeConn(); ResultSet rs = conn.sqlQuery(sqlStr); if (rs == null) { System.out.println("no data satisfied data ,please check..."); return null; } ResultSetMetaData meta = null; int numRecords = 0; int condition_num = 0; try { meta = rs.getMetaData(); int numCols = meta.getColumnCount(); data = new DataItems(); while (rs.next()) { numRecords++; String time = rs.getString(1).trim(); Date d = parseTime(time); // 将数值时间转化为标准时间格式 String srcIp = rs.getString(2); // source IP String destIp = rs.getString(3); // destination IP String traffic = rs.getString(4); // traffic if (srcIp.compareTo(whichIp) == 0 || destIp.compareTo(whichIp) == 0) { lastYear.add(Calendar.HOUR_OF_DAY, 1); dataItems.add1Data(lastYear.getTime(), traffic); } } rs.close(); } catch (SQLException e) { e.printStackTrace(); } System.out.println("该表总记录数:" + numRecords + " 满足条件的记录数有:" + condition_num); // System.out.println("锟斤拷取锟斤拷锟�" + data.getLength() + "锟斤拷锟斤拷录锟斤拷"); return data; }