Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //CRIAR LEIL�O
- public String create_auction(long code, String title, String description, String Date, int amount, String username) throws RemoteException {
- //type: login, username: imota, password: cenasmalucas3
- //type: create_auction, code: 9780451524935, title: 1984, description: big brother i s watching you, deadline: 2017-01-01 00:01, amount: 10
- int check = 0;
- String resultado;
- //-------------------------------------
- //Verificar se o registo pode ser feito;
- //-------------------------------------
- Statement myStmt;
- try {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Date date2 = format.parse(getcurrentdate());
- Date date = format.parse(Date);
- if (date.compareTo(date2) < 0) {
- return "type: create_auction, ok: false";
- }
- myStmt = myConn.createStatement();
- ResultSet myRs = myStmt.executeQuery("SELECT ID_USERS\n"
- + "FROM users\n"
- + "WHERE USERNAME ='" + username + "'");//results set
- if (myRs.next()) {
- int id_user = myRs.getInt("ID_USERS");
- String commandSql = "INSERT INTO auction (CODE, TITLE, DESCRIPTION, DEADLINE, ID_USER, AUCTION_STATE)\n"
- + "values (" + code + ", '" + title + "', '" + description + "', '" + Date + "', " + id_user + ", 'active')";
- myStmt.executeUpdate(commandSql); //results set
- //para a bid, preciso de saber o ID_AUCTION
- ResultSet myRs2 = myStmt.executeQuery("SELECT ID_AUCTION "
- + "FROM auction "
- + "WHERE (CODE =" + code + " AND TITLE='" + title + "' AND DESCRIPTION='" + description + "' AND DEADLINE='" + Date + "' AND ID_USER=" + id_user + " AND AUCTION_STATE='active')");
- //myRs2.next();
- myRs2.last();
- //adiciona ao array das deadlines a data final da auction
- client.writetodeadlinearray(myRs2.getInt("ID_AUCTION"),Date);
- //acrescento a tabela de bids
- String commandSql2 = "INSERT INTO bids (AMOUNT, ID_AUCTION, ID_USER, BID_STATE)\n"
- + "values (" + amount + ", " + myRs2.getInt("ID_AUCTION") + ", " + id_user + ", 'active')";
- myStmt.executeUpdate(commandSql2);
- check = 1;
- }
- } catch (SQLException e) {//tratar exception de limite de carateres
- check = 0;
- e.printStackTrace();
- } catch (java.text.ParseException ex) {
- Logger.getLogger(RMIServer.class.getName()).log(Level.SEVERE, null, ex);
- }
- //-----------------------------------
- //Verificar se o leil�o foi criado
- //-----------------------------------
- if (check == 1) {
- resultado = "type: create_auction, ok: true";
- } else {
- resultado = "type: create_auction, ok: false";
- }
- return resultado;
- }
Add Comment
Please, Sign In to add comment