Java 将cmr值插入数据库

Java 将cmr值插入数据库,java,database,netbeans,csv,Java,Database,Netbeans,Csv,我有一个不同值的CMR文件,但我不知道如何使用分隔符。 我想使用带按钮的java netbeans将“numberPacketsLost”、“jitter”和“latency”存储到mySQL数据库中 谢谢!:) cmr文件中的代码: "cdrRecordType","globalCallID_callManagerId","globalCallID_callId","nodeId","directoryNum","callIdentifier","dateTimeStamp","numberP

我有一个不同值的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"

您需要打开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();
}
BufferedReader br=new BufferedReader(new FileReader(新文件(“myCmrFile”));
字符串行=null;
int linecount=0;
而((line=br.readLine())!=null){
if(linecount++<2)//跳过标题
继续;
//拆分数据并转换为整数
String[]data=line.split(“,”);
整型packetsLost=Integer.valueOf(数据[10]);
整数抖动=整数.valueOf(数据[11]);
整数延迟=Integer.valueOf(数据[12]);
//现在插入数据库,查询将如下所示
String query=“插入myTable(numberPacketsLost、抖动、延迟)值(?,?)”;
PreparedStatement ps=connection.PrepareStation(查询);
ps.setInt(1个,包装成本);
ps.setInt(2,抖动);
ps.setInt(3,延迟);
ps.executeUpdate();
}

这段代码无法正常工作,您需要根据数据库的实际值对其进行更改

是的!!我需要java代码来提取数据!!你能做你提到的任何部分吗?从文件读取、拆分字符串、编写mySQL查询?谢谢:)获得帮助^^,但我想从cmr文件自动创建表,然后我将3个值插入其中,如果我可以的话,如何操作!!我的数据库是mysql,我使用mysql工作台!!再次感谢:)问题是第二行是数据类型阻止将整数值插入到基中!!当我在应用程序中单击按钮时,我看到以下消息:java.lang.NumberFormatException:对于输入字符串:“numberPacketLost”,您需要跳过标题。所以再跳过一行