2013-05-19 28 views
0

我有一個CMR文件具有不同的值,但我不知道如何使用分隔符。 我想使用帶有按鈕的java netbeans將「numberPacketsLost」,「jitter」和「latency」存儲到mySQL數據庫中。插入cmr值到數據庫

謝謝! :)從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

是的!我需要Java代碼來提取數據! –

+0

你可以做你提到的任何部分嗎?從文件讀取,分割字符串,寫一個mySQL查詢? – greedybuddha

回答

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(); 
} 

此代碼將不完全工作,你需要根據你的數據庫的真實值周圍改變它。

+0

謝謝:)尋求幫助^^,但我想從cmr文件自動創建表,然後我插入3值,如果我能如何做到這一點!我的數據庫是MySQL,我使用mysql工作臺!再次感謝:) –

+0

問題是,第二行是數據類型塊插入到基地的整數值! –

+0

當我點擊應用程序中的按鈕我有這條消息: –