public static void createLoan(Loan loan){

    Connection con = null;

    try {
        con = JDBCConnectionFactory.getInstance().getNewConnection();
        String sql = "";

        sql = "INSERT INTO loan (users_id, book_id, loan_date, loan_dueDate) "
                + "VALUES (?, ?, CURDATE(), DATE_ADD(CURDATE(),INTERVAL 30))";
        PreparedStatement prep = con.prepareStatement(sql);
        prep.setLong(1, loan.user.getDatabaseId());
        prep.setLong(2, loan.book.getDatabaseId());


为什么不能使用DATE_ADD功能设置特定日期?它只返回Null

最佳答案

DATEADD方法示例:

SELECT OrderId,DATEADD(day,45,OrderDate) AS OrderPayDate
FROM Orders


检查一下:http://www.w3schools.com/sql/func_dateadd.asp

10-06 01:06