我使用OpenCSV Reader - java加载我的CSV文件(文件大小:-1.47 GB(1,585,965,952字节))。
然而,在我的编码中,每当它只设法将10950记录插入PostgreSQL数据库。
CSVReader csvReader = new CSVReader(new FileReader(csvFilename));
String[] row = null;
String sqlInsertCSV = "insert into ip2location_tmp_test
(ip_from, ip_to, xxxxx, "
+ "xxxxx, xxxxx,xxxxx, "
+ "xxxxx,xxxxx, xxxxx, xxxxx, xxxxx, xxxxx,xxxxx,xxxxx)"
+ " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
while((row = csvReader.readNext()) != null) {
PreparedStatement insertCSV = conn.prepareStatement(sqlInsertCSV);
insertCSV.setLong(1, Long.parseLong(row[0]));
....
....
insertCSV.setString(14, row[13]); // usage_type
insertCSV.executeUpdate();
}
csvReader.close();
PreparedStatement insertCSV = conn.prepareStatement(sqlInsertCSV);
insertCSV.executeUpdate();
}
OpenCSV有限制吗?
我需要使用setString函数来满足PostgreSQL中的单引号。
答案 0 :(得分:0)
没有错误。它就像那样停止了
嗨克雷格, COPY命令需要是超级用户。之前已经尝试过了
答案 1 :(得分:0)
第一个问题:您告诉我们文件中有多少字节,但文件中有多少条记录(行)?如果文件有10950行,那么一切都很好。
第二个问题:为什么在while循环之外有prepareStatement / executeUpdate?在我看来,它会尝试插入最后一条记录两次或插入一条空记录,因为一旦你在外面没有数据,因为csvReader返回null。
使用您正在使用的记录方法,您可以阅读的记录数量没有限制。检查您的数据文件,看看第10950行附近的文件中是否没有意外回车。