private int insertData2cancel( String user_id, String service_id, String command_code, String mlist, MsgObject msgObject, String mtfree, int msgtype, String Service_ss_id, String mt_count) { int ireturn = 1; Connection connection = null; DBPool dbpool = new DBPool(); // long lmilisec = System.currentTimeMillis(); String sqlInsert = "Insert into " + mlist + "_cancel(user_id, service_id, date,command_code,request_id, message_type,mobile_operator,mt_free,mt_count) values ('" + user_id + "','" + service_id + "','" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "','" + Service_ss_id + "','" + msgObject.getRequestid() + "','" + msgtype + "','" + msgObject.getMobileoperator() + "'," + mtfree + "," + mt_count + ")"; try { connection = dbpool.getConnectionGateway(); if (DBUtil.executeSQL(connection, sqlInsert) < 0) { Util.logger.error( this.getClass().getName() + "" + ": uppdate Statement: Insert " + mlist + " Failed:" + sqlInsert); ireturn = -1; } } catch (Exception ex) { Util.logger.error(this.getClass().getName() + ":Insert " + mlist + " Failed"); ireturn = -1; Util.logger.printStackTrace(ex); } finally { dbpool.cleanup(connection); } return ireturn; }
private String[] checkSession() { String[] kq = new String[20]; String newSession = "-1"; String Winner = "-1"; String WinnerPrice = "xxx"; String WinnerUser = "******"; String begintime = "xxx"; String endtime = "xxx"; String sp = "xxx"; Connection connection = null; PreparedStatement statement = null; ResultSet rs = null; DBPool dbpool = new DBPool(); try { connection = dbpool.getConnectionGateway(); if (connection == null) { Util.logger.error("Impossible to connect to DB"); } String query1 = "select phien from tbphien"; statement = connection.prepareStatement(query1); String phienTemp = ""; if (statement.execute()) { rs = statement.getResultSet(); while (rs.next()) { phienTemp = rs.getString(1); Util.logger.info("Phientemp:" + phienTemp); } } dbpool.cleanup(rs, statement); // int phien = Integer.parseInt(kq[0]); int phien = Integer.parseInt(phienTemp); // check xem da ket thuc phien hay chua. Neu da ket thuc phien thi // tim nguoi trung thuong String query2 = "select * from daugia_phien where current_timestamp >" + " endtime and phien=" + phien; statement = connection.prepareStatement(query2); if (statement.execute()) { rs = statement.getResultSet(); if (rs.next()) { newSession = "1"; Util.logger.info("newSession:" + newSession); phien = phien + 1; String sqlUpdate = "update tbphien set phien=" + phien; DBUtil.executeSQL(connection, sqlUpdate); DBUtil.executeSQL( connection, "insert into daugia_phien(phien,begintime,endtime) select phien + 1,adddate(begintime,7),adddate(endtime,7) from daugia_phien where phien=" + (phien - 1)); } } dbpool.cleanup(rs, statement); String query5 = "select begintime,endtime,sanpham from daugia_phien where phien=" + phien; statement = connection.prepareStatement(query5); if (statement.execute()) { if (statement.execute()) { rs = statement.getResultSet(); while (rs.next()) { begintime = rs.getString(1); endtime = rs.getString(2); sp = rs.getString(3); Util.logger.info("begintime:" + begintime + "endtime: " + endtime); } } } kq[0] = phienTemp; kq[1] = newSession; kq[2] = begintime; kq[3] = endtime; kq[4] = sp; } catch (SQLException ex2) { Util.logger.error("checkSession. Ex:3" + ex2.toString()); } catch (Exception ex3) { Util.logger.error("checkSession. Ex3:" + ex3.toString()); } finally { dbpool.cleanup(rs, statement); dbpool.cleanup(connection); } return kq; }