如何为SqlFormatter解析LocalDate数据

时间:2018-10-19 08:31:47

标签: java mysql maven localdate

伙计们我已经解决了这个问题,但现在我遇到了其他错误:) 我的方法返回null。 第一个系统设置是正确的 最后一个系统设置为空

@Override
public Employee saveEmployee(Employee employee) throws SQLException {
    System.out.println("Received emp: " + employee);
    String sql = "";
    Random random = new Random();
    employee.setId(1990000000000L + random.nextInt(1000000000));
    System.out.println(1990000000000L + random.nextInt(1000000000));

    if (employee.getId() == null) {

        sql = String.format(
                "UPDATE employees SET idemployees = '%d' , firstName = '%s', lastName = '%s' ,birthDay = '%s' WHERE idemployees = '%d'",
                employee.getId(), employee.getFirstName(), employee.getLastName(), employee.getBirthDay(),
                employee.getId());
    } else {
        DateConvert convert = new DateConvert();

        LocalDate dateToConvert = employee.getBirthDay();
        System.out.println(DateConvert.convertToDateViaInstant(employee.getBirthDay()));
        sql = String.format(
                "INSERT INTO employees (idemployees,firstName,lastName,birthDay) VALUES ('%d','%s','%s','%s')",
                employee.getId(), employee.getFirstName(), employee.getLastName(), employee.getBirthDay());
        employee = getEmployee(employee.getId());
    }

    System.out.println(sql);
    boolean rs = SendInsertQuery(sql);
    System.out.println("saved employee" + employee);

    return employee;
}
Received emp: Employee{id=232323233, firstName='Tarek', lastName='Abaza', birthDay=1990-01-04}
1990895219625
Thu Jan 04 00:00:00 CET 1990
INSERT INTO employees (idemployees,firstName,lastName,birthDay) VALUES ('1990500456506','Tarek','Abaza','1990-01-04')
Received emp: null

0 个答案:

没有答案