我有一个具有不同值的CMR文件,但我不知道如何使用分隔符。 我想使用带有按钮的java netbeans将“numberPacketsLost”,“jitter”和“latency”存储到mySQL数据库中。
谢谢! :)
cmr文件中的代码:
"cdrRecordType","globalCallID_callManagerId","globalCallID_callId","nodeId","directoryNum","callIdentifier","dateTimeStamp","numberPacketsSent","numberOctetsSent","numberPacketsReceived","numberOctetsReceived","numberPacketsLost","jitter","latency","pkid","directoryNumPartition","globalCallId_ClusterID","deviceName","varVQMetrics"
INTEGER,INTEGER,INTEGER,INTEGER,VARCHAR(50),INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,UNIQUEIDENTIFIER,VARCHAR(50),VARCHAR(50),VARCHAR(129),VARCHAR(600)
2,2,1732470,2,"4241",47660016,1319556369,192,33024,191,32852,0,0,0,"8ea4f719-c49c-4456-a2a8-972ebcfb57a9","2b494acb-9359-7f52-b0ef-7b66bb672b73","StandAloneCluster","SEP0026CB3C2A16","MLQK=0.0000;MLQKav=0.0000;MLQKmn=0.0000;MLQKmx=0.0000;ICR=0.0000;CCR=0.0000;ICRmx=0.0000;CS=0;SCS=0;MLQKvr=0.95"
2,2,1732447,2,"5352",47659963,1319556371,1409,242348,1408,242176,0,0,0,"61ca6d9f-8e75-4282-b303-3fea2fa75df7","2b494acb-9359-7f52-b0ef-7b66bb672b73","StandAloneCluster","SEP64168D506D26","MLQK=4.5000;MLQKav=4.3554;MLQKmn=4.1440;MLQKmx=4.5000;ICR=0.0000;CCR=0.0029;ICRmx=0.0263;CS=1;SCS=1;MLQKvr=0.95"
2,2,1732134,2,"5502",47658367,1319556373,28529,4906988,28537,4908364,0,0,0,"d1717925-89bf-41b4-b122-6162db89128f","2b494acb-9359-7f52-b0ef-7b66bb672b73","StandAloneCluster","SEP64168D50A4DB","MLQK=4.5000;MLQKav=4.4570;MLQKmn=4.1440;MLQKmx=4.5000;MLQKvr=0.95;CCR=0.0011;ICR=0.0000;ICRmx=0.0267;CS=9;SCS=9"
答案 0 :(得分:0)
您需要打开cmr文件,逐行读取标题并提取数据。获得所需数据后,只需编写一个插入数据库的查询。
BufferedReader br = new BufferedReader(new FileReader(new File("myCmrFile")));
String line = null;
int linecount = 0;
while ((line = br.readLine()) != null){
if (linecount++ < 2) // skip the headers
continue;
// split the data and convert to integers
String[] data = line.split(",");
Integer packetsLost = Integer.valueOf(data[10]);
Integer jitter = Integer.valueOf(data[11]);
Integer latency = Integer.valueOf(data[12]);
// now insert into the db, query will look something like this
String query = "INSERT INTO myTable (numberPacketsLost, jitter, latency) VALUES(?,?,?)";
PreparedStatement ps = connection.prepareStatment(query);
ps.setInt(1, packetsLost);
ps.setInt(2, jitter);
ps.setInt(3, latency);
ps.executeUpdate();
}
此代码无法正常工作,您需要根据数据库的实际值进行更改。