我有一个包含一些数据的文本文件。当我尝试将数据放入 MySQL 时,我收到此错误“ java.lang.OutOfMemoryError: Java heap space
”。
我的代码:
try {
// create a buffer reader
java.io.BufferedReader br = new BufferedReader(new FileReader(f));
// define line
String line = null;
// connect to the database
connect = (Connection) DbConnection.establishConnection();
while ((line = br.readLine()) != null) {
// create preparedStatement
preparedStatement = (PreparedStatement) connect.prepareStatement("insert into IdentifiedExpertList values (?,?)");
String[] rowData = line.split("\\s+", 2);
String firstColumnData = rowData[0];
String secondColumnData = null;
if (rowData[1].trim().isEmpty()) {
secondColumnData = null;
} else {
secondColumnData = rowData[1];
}
preparedStatement.setString(1, firstColumnData.trim());
preparedStatement.setString(2, secondColumnData);
preparedStatement.executeUpdate();
}
br.close();
}