Solved problem with wrong insert into the db.

This commit is contained in:
Marcin Woźniak 2020-08-04 17:56:59 +02:00 committed by Marcin Wozniak
parent 90cc284f7a
commit 4eabc194fc
3 changed files with 23 additions and 5 deletions

View File

@ -38,6 +38,7 @@ public class FileReader {
while (cellIt.hasNext()) {
Cell c = cellIt.next();
keys.put(c.toString(), index);
index+=1;
}
rowIt.remove();

View File

@ -6,6 +6,7 @@ import com.plannaplan.entities.Lecturer;
import com.plannaplan.models.FileData;
import com.plannaplan.services.LecturerService;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
public class FileToDatabaseMigrator {
@ -28,12 +29,28 @@ public class FileToDatabaseMigrator {
while (rows.hasNext()) {
Row row = rows.next();
Lecturer newLecturer = new Lecturer(row.getCell(title_index).toString(), row.getCell(name_index).toString(),
row.getCell(surname_index).toString());
System.out.println(newLecturer.getSurname());
System.out.println(newLecturer.getName());
System.out.println(newLecturer.getTitle());
Cell title_cell = row.getCell(title_index);
Cell name_cell = row.getCell(name_index);
Cell surname_cell = row.getCell(surname_index);
String lecturer_title = "";
String lecturer_surname = "";
String lecturer_name = "";
if (title_cell != null) {
lecturer_title = title_cell.toString();
}
if (name_cell != null) {
lecturer_name = name_cell.toString();
}
if (surname_cell != null) {
lecturer_surname = surname_cell.toString();
}
Lecturer newLecturer = new Lecturer(lecturer_title, lecturer_name, lecturer_surname);
lecturerService.save(newLecturer);
}
}