/** * Inserts a new entry in the `session` table. * * @param id I * @param root * @return A unique key associated with the user * @throws InstantiationException * @throws IllegalAccessException * @throws ClassNotFoundException * @throws SQLException */ public static String insertSession(int id, boolean root) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException { /* SESSION_HOUR_DURATIONS starting from now */ Timestamp expires = new Timestamp(System.currentTimeMillis() + SESSION_HOUR_DURATION * 60 * 60 * 1000); String key = generateKey(); String sql = "INSERT INTO `session` " + "(`key`, `user_id`, `expires`, `root`)" + " VALUE(?,?,?,?)"; Connection connection = DataBaseUtils.getMySQLConnection(); PreparedStatement ps = (PreparedStatement) connection.prepareStatement(sql); ps.setString(1, key); ps.setInt(2, id); ps.setTimestamp(3, expires); ps.setBoolean(4, root); ps.executeUpdate(); System.out.println("Session inserted for id : " + id); ps.close(); connection.close(); return key; }
/** * @param issueNumber * @param fast3CountList * @throws SQLException 四码预测插入预测计划方法 */ private void insertData2Db(String issueNumber, List<Fast3Count> fast3CountList) throws SQLException { Connection conn = ConnectSrcDb.getSrcConnection(); String sql = "insert into " + App.simaTbName + " (YUCE_ISSUE_START,YUCE_ISSUE_STOP,DROWN_PLAN,CREATE_TIME) values(?,?,?,?)"; String code1 = App.getNextIssueByCurrentIssue(issueNumber); String code2 = App.getNextIssueByCurrentIssue(code1); String code3 = App.getNextIssueByCurrentIssue(code2); int[] numArr = { fast3CountList.get(0).getNumber(), fast3CountList.get(1).getNumber(), fast3CountList.get(2).getNumber(), fast3CountList.get(3).getNumber() }; Arrays.sort(numArr); PreparedStatement pstmt = (PreparedStatement) conn.prepareStatement(sql); pstmt.setString(1, code1); pstmt.setString(2, code3); pstmt.setString( 3, Integer.toString(numArr[0]) + Integer.toString(numArr[1]) + Integer.toString(numArr[2]) + Integer.toString(numArr[3])); pstmt.setTimestamp(4, new java.sql.Timestamp(new Date().getTime())); pstmt.executeUpdate(); }