src/main/java/com/hwua/erhai/dao/impl/RecordDaoImpl.java

(开头部分) 14KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

package com.hwua.erhai.dao.impl;

import com.hwua.erhai.dao.IRecordDao;
import com.hwua.erhai.entity.Record;
import com.hwua.erhai.jdbc.*;
import com.hwua.erhai.util.Util;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class RecordDaoImpl extends JDBCTemplate implements IRecordDao {

    @Override
    public long addRecord(Connection conn, final long userId, final long carId) {
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        long id;
        String sql = "INSERT INTO t_record (id, user_id, car_id, start_date)"
                + " VALUES(null,?,?,?)";
        try {
            // 执行SQL语句
            pstmt = conn.prepareStatement(
                    sql, Statement.RETURN_GENERATED_KEYS);
            pstmt.setLong(1, userId);
            pstmt.setLong(2, carId);
            pstmt.setString(3, Util.today());
            pstmt.executeUpdate();

            // 获取自增主键id
            rs = pstmt.getGeneratedKeys();
            rs.next();
            id = rs.getInt(1);
        } catch (SQLException e) {
            throw new RuntimeException(String.format("failed to execute sql[%s]", sql), e);
        } finally {
            DBUtil.close(rs, pstmt);
        }

        // 返回的id是新增记录的主键
        return id;
    }


    //修改
    @Override
    //Connection conn, long recordId, String returnTime, double payment,final long id,final long carId
    public int updateRecord(Connection conn, final long recordId, final String returnTime, final double payment,
                            final long id, final long carId) {

        PreparedStatement pstmt = null;
        String sql = "update t_record set return_date=?,payment=? where car_id=?";
        try {
            // conn=ConnectionFactory.getConnection();
            pstmt = conn.prepareStatement(
                    sql, Statement.RETURN_GENERATED_KEYS);
            //PreparedStatement pstm = conn.prepareStatement(sql);

            pstmt.setString(1, Util.today());
            pstmt.setDouble(2, payment);
后面还有 315 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。