我正在创建一个简单的应用程序,它使用 JDBC 从 MySQL 获取数据。我使用 dao 从数据库中获取数据。除了一个以外,其他都工作正常(所有 DAO 的代码都相同)。我也手动提交 INSERT 和 UPDATE 方法。即使我手动设置隔离级别 read committed,Workbench 也会返回有效结果。JDBCSessionDao 创建方法:public void create(Session session) throws SQLException{ try(PreparedStatement ps = conn.prepareStatement(INSERT_SESSION)){ conn.setAutoCommit(false); LocalTime start = session.getStartTime(); LocalTime end = session.getEndTime(); System.out.println(start + ", " + end); System.out.println(Time.valueOf(start) + ", " + Time.valueOf(end)); ps.setTime(1, Time.valueOf(start)); ps.setTime(2, Time.valueOf(end)); ps.setDate(3, Date.valueOf(session.getDate())); ps.setLong(4, session.getMovieId()); ps.executeUpdate(); conn.commit(); conn.setAutoCommit(true); } catch (SQLException e){ logger.error(e.getMessage()); conn.rollback(); } }JDBCSessionDao findByDate 方法public List<Session> findByDate(LocalDate date) { List<Session> sessions = new ArrayList<>(); SessionMapper mapper = new SessionMapper(); try(PreparedStatement ps = conn.prepareStatement(SELECT_BY_DATE_ORDER_BY_TIME_ASC)){ ps.setDate(1, Date.valueOf(date)); ResultSet rs = ps.executeQuery(); System.out.println(rs.getFetchSize()); while(rs.next()){ Session s = mapper.extractFromResultSet(rs); sessions.add(s); } } catch (SQLException e){ logger.error(e.getMessage()); } return sessions;}询问:String SELECT_BY_DATE_ORDER_BY_TIME_ASC = "SELECT * FROM sessions WHERE session_date=? ORDER by start_time ASC";JDBCDaoFactory getConnection() 方法:private Connection getConnection(){ String url = "jdbc:mysql://localhost:3306/cinemajee?useLegacyDatetimeCode=false&serverTimezone=Europe/Kiev"; String user = "root"; String password = "root";
添加回答
举报
0/150
提交
取消