Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am having a spring boot application which reads values from the Microsoft access file and then checks if the value exists in the database then gets updated or else inserted as the new record however I'm only getting these values present in the database and I'm not able to get the values which are missing from the database I don't know where I'm doing it wrong but here is the code I have

What I have tried:

Model Class

    @Table(name = "tbl_tests")
    public class Test {
        @GeneratedValue(strategy = GenerationType.SEQUENCE)
        private Long id;
        private String customId;
        private String testTypeId;
        private LocalDateTime testDate;
        private LocalDateTime resultDate;
        private Float resultNumeric;


public interface TestRepository extends JpaRepository<Test, Long> {
  @Query(value = "select t from Test t where t.customId =:customId and t.testDate =:testDate and t.testTypeId =:testType")
  Test findByTestParams(String customId, LocalDateTime testDate, String testType);

service class

public class TestProcessingService {

    private TestRepository testRepository;
    public void processData(Path filepath) throws IOException, SQLException {
    List<Test> testList = new ArrayList<>();
    Table table = File(filepath.toString())).getTable("tblTests");
    for(Row row : table) {
    Test dbData = testRepository.findByTestParams(row.get("CustomID"), (LocalDateTime) row.get("TestDate"), (String) row.get("TestTypeID"));
    if(dbData == null) {
    Test test = new Test();
    test.setTestTypeId((String) row.get("TestTypeID"));
    test.setTestDate((LocalDateTime) row.get("TestDate"));
    test.setResultNumeric((Float) row.get("ResultNumeric"));
    } else {
     dbData.setTestTypeId((String) row.get("TestTypeID"));
     dbData.setTestDate((LocalDateTime) row.get("TestDate"));
     dbData.setResultNumeric((Float) row.get("ResultNumeric"));

Api Class

public class UploadApi {
    private DataUploadService dataUploadService;

    protected UploadResponse uploadFile(@RequestParam MultipartFile file) throws IOException,SQLException {
    return dataUploadService.uploadFile(file);

I'm not able to get the null values so that I can insert them as a new record, I'm only getting the values that are present inside the database. Any suggestions will be much appreciated.

Also there is more than one customId present in table test.
Updated 7-May-23 23:24pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900