Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无效); //ps.setInt(4,item.getItemId()); //ps.setInt(5,mit.getType()); //ps.setInt(6,item.getPosition()); //ps.setInt(7,item.getQua_Java_Mysql - Fatal编程技术网

Java 无效); //ps.setInt(4,item.getItemId()); //ps.setInt(5,mit.getType()); //ps.setInt(6,item.getPosition()); //ps.setInt(7,item.getQua

Java 无效); //ps.setInt(4,item.getItemId()); //ps.setInt(5,mit.getType()); //ps.setInt(6,item.getPosition()); //ps.setInt(7,item.getQua,java,mysql,Java,Mysql,无效); //ps.setInt(4,item.getItemId()); //ps.setInt(5,mit.getType()); //ps.setInt(6,item.getPosition()); //ps.setInt(7,item.getQuantity()); //ps.setString(8,item.getOwner()); //ps.setInt(9,item.getPetId()); //ps.setInt(10,item.getFlag()); //ps.setLong(

无效); //ps.setInt(4,item.getItemId()); //ps.setInt(5,mit.getType()); //ps.setInt(6,item.getPosition()); //ps.setInt(7,item.getQuantity()); //ps.setString(8,item.getOwner()); //ps.setInt(9,item.getPetId()); //ps.setInt(10,item.getFlag()); //ps.setLong(11,item.getExpiration()); //ps.setString(12,item.getGiftFrom()); 已保存的\u项。添加(对); ps.addBatch(); } ps.executeBatch(); System.out.println(“保存项目的时间”+(System.currentTimeMillis()-start)); start=System.currentTimeMillis(); System.out.println(“设备前的权利”); try(ResultSet rs=ps.getGeneratedKeys()){ 对于(配对项:已保存的_项){ int键=-1; 如果(rs.next()){ key=rs.getInt(1); } 如果(键==0){ key=item.getLeft().getInventoryItemId(); } worker.batch(项目、密钥、id); MapleInventoryType mit=item.right; if(mit.equals(MapleInventoryType.Equipment)| mit.equals(MapleInventoryType.Equipment)){ pse.setInt(1,键); 装备=(装备)项。左; pse.setInt(2,装备getUpgradeSlots()); pse.setInt(3,装备.getLevel()); pse.setInt(4,equipment.getStr()); pse.setInt(5,装备.getDex()); pse.setInt(6,equipment.getInt()); pse.setInt(7,装备getLuk()); pse.setInt(8,equipment.getHp()); pse.setInt(9,equipment.getMp()); pse.setInt(10,装备getWatk()); pse.setInt(11,装备getMatk()); pse.setInt(12,装备.getWdef()); pse.setInt(13,装备.getMdef()); pse.setInt(14,装备getAcc()); pse.setInt(15,装备.getAvoid()); pse.setInt(16,装备getHands()); pse.setInt(17,装备.getSpeed()); pse.setInt(18,装备.getJump()); pse.setInt(19,装备getvice()); pse.setInt(20,装备.getItemLevel()); pse.setInt(21,装备.getItemExp()); pse.setInt(22,equipment.getRingId()); pse.setBoolean(23,装备haskill()); pse.addBatch(); } } pse.executeBatch(); } } worker.executeBatch(id); } System.out.println(“保存设备的时间”+(System.currentTimeMillis()-start)); }捕获(例外e){ LogHelper.GENERAL_EXCEPTION.get().info(“ItemFactory saveItems:+e); }最后{ worker.close(); lock.unlock(); } }
实际查询/语句在哪里?MySQL没有预先准备好的语句AFAIK的概念。好的,我会更新帖子。等一下@TimBiegeleisen I用适当的声明更新了帖子。请注意,MySQL one在Java中是等效的,只是预插入了数据。如果使用批处理,我将创建一个方法,该方法接受一条语句和要添加到
INSERT
中的参数。但是批处理方法会创建一个语句。对我来说,这似乎是一个糟糕的设计选择。相反,只需让它向批处理中添加另一个insert即可。@jonathannguen这里有一种可能的调试方法。在运行调试器的java中修改一个表,以便可以单步执行它。在命令行上修改其他表。(当然,它必须是与约束相关的行。)通过在调试器中一次一行地遍历代码,您应该能够准确地知道行锁何时被释放,因为命令行应该一直阻塞到释放为止。实际的查询/语句在哪里?MySQL没有预先准备好的语句AFAIK的概念。好的,我会更新帖子。等一下@TimBiegeleisen I用适当的声明更新了帖子。请注意,MySQL one在Java中是等效的,只是预插入了数据。如果使用批处理,我将创建一个方法,该方法接受一条语句和要添加到
INSERT
中的参数。但是批处理方法会创建一个语句。对我来说,这似乎是一个糟糕的设计选择。相反,只需让它向批处理中添加另一个insert即可。@jonathannguen这里有一种可能的调试方法。在运行调试器的java中修改一个表,以便可以单步执行它。在命令行上修改其他表。(当然,它必须是一个与约束相关的行。)通过在调试器中一次一行地遍历代码,您应该能够准确地知道行锁何时被释放,因为命令行应该一直阻塞到释放为止。
CREATE TABLE `inventory_items` (
  `inventoryitemid` int(11) unsigned NOT NULL,
  `characterid` int(11) DEFAULT NULL,
  `inventorytype` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`inventoryitemid`),
  KEY `charid` (`characterid`),
  CONSTRAINT `INVENTORYITEM_FK` FOREIGN KEY (`inventoryitemid`) REFERENCES `items` (`inventoryitemid`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1
CREATE TABLE `items` (
  `inventoryitemid` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `itemid` int(11) NOT NULL DEFAULT '0',
  `quantity` int(11) NOT NULL DEFAULT '0',
  `owner` tinytext NOT NULL,
  `petid` int(11) NOT NULL DEFAULT '-1',
  `flag` int(11) NOT NULL,
  `expiration` bigint(20) NOT NULL DEFAULT '-1',
  `giftFrom` varchar(26) NOT NULL,
  `position` tinyint(4) DEFAULT NULL,
  PRIMARY KEY (`inventoryitemid`)
) ENGINE=InnoDB AUTO_INCREMENT=733 DEFAULT CHARSET=latin1
con.prepareStatement("INSERT INTO inventory_items (inventoryitemid, characterid, inventorytype) VALUES (?, ?, ?)");
INSERT INTO inventory_items (inventoryitemid, characterid, inventorytype) VALUES (730, 38843, 3)
@Override
        public void batch(Pair<Item, MapleInventoryType> entry, int key, int id) {
            try {
                if (ps.isClosed())
                    ps = con.prepareStatement("INSERT INTO inventory_items (inventoryitemid, characterid, inventorytype) VALUES (?, ?, ?)");
                //System.out.println("Batching! " + ps.isClosed());
                System.out.println("KEY IS " + key);
                ps.setInt(1, key);
                ps.setInt(2, id);
                ps.setInt(3, entry.getRight().getType());
                ps.addBatch();
            } catch (Exception e) {
                LogHelper.GENERAL_EXCEPTION.get().info("InventoryWorker batch: " + e);
            }

        }

        @Override
        public void executeBatch(int id) throws SQLException {
            // TODO Auto-generated method stub
            try (PreparedStatement delete = con.prepareStatement("DELETE FROM items WHERE EXISTS (SELECT * FROM inventory_items WHERE inventory_items.inventoryitemid = items.inventoryitemid AND characterid = ?)")) {
                System.out.println("DELETE BY " + id); 
                delete.setInt(1, id);
                delete.execute(); 

                if (!ps.isClosed()) {
                    ps.executeBatch();
                }
            } catch (SQLException e) {
                LogHelper.GENERAL_EXCEPTION.get().info("InventoryWorker executeBatch: " + e);
            } finally {
                ps.close();
            }
        }
    public void saveItems(List<Pair<Item, MapleInventoryType>> items, int id, Connection con) throws SQLException {
        lock.lock();
        long start = System.currentTimeMillis();
//        StringBuilder query = new StringBuilder();
//        query.append(
//                "UPDATE `inventoryitems` SET characterid = -1 WHERE `");
//        query.append(account ? "accountid" : "characterid").append("` = ? AND `type` = ? LIMIT 128");
        try {
//            try (PreparedStatement ps = con.prepareStatement(query.toString())) {                
//                ps.setInt(1, id);
//                ps.setInt(2, value);
//                ps.executeUpdate();
//            } catch (Exception e) {
//              LogHelper.GENERAL_EXCEPTION.get().info("ItemFactory updateItems: " + e);
//            }
            System.out.println("Time to delete items " + (System.currentTimeMillis() - start));
            start = System.currentTimeMillis();
            try (PreparedStatement ps = con.prepareStatement("INSERT INTO `items` (`itemid`"+
                    ", `quantity`, `owner`, `petid`, `flag`, `expiration`, `giftFrom`, `position`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
                 Statement.RETURN_GENERATED_KEYS);
                 PreparedStatement pse = con.prepareStatement(
                 "INSERT INTO `inventoryequipment` (`inventoryequipmentid`, `inventoryitemid`, `upgradeslots`, `level`, `str`, `dex`, `int`"+
                 ", `luk`, `hp`, `mp`, `watk`, `matk`, `wdef`, `mdef`, `acc`, `avoid`, `hands`, `speed`, `jump`, `vicious`, `itemLevel`, `itemexp`, `ringid`, `skill`) VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
                ) {

                LinkedList<Pair<Item, MapleInventoryType>> saved_items = new LinkedList<>();

                if (!items.isEmpty()) {
                    for (Pair<Item, MapleInventoryType> pair : items) {
                        Item item = pair.getLeft();
                        if (item.disappearsAtLogout())
                            continue;
                        MapleInventoryType mit = pair.getRight();
                        ps.setInt(1, item.getItemId());
                        ps.setInt(2, item.getQuantity());
                        ps.setString(3, item.getOwner());
                        ps.setInt(4, item.getPetId());
                        ps.setInt(5, item.getFlag());
                        ps.setLong(6, item.getExpiration());
                        ps.setString(7, item.getGiftFrom());
                        ps.setInt(8, item.getPosition());
//                        ps.setInt(1, value);
//                        ps.setString(2, account ? null : String.valueOf(id));
//                        ps.setString(3, account ? String.valueOf(id) : null);
//                        ps.setInt(4, item.getItemId());
//                        ps.setInt(5, mit.getType());
//                        ps.setInt(6, item.getPosition());
//                        ps.setInt(7, item.getQuantity());
//                        ps.setString(8, item.getOwner());
//                        ps.setInt(9, item.getPetId());
//                        ps.setInt(10, item.getFlag());
//                        ps.setLong(11, item.getExpiration());
//                        ps.setString(12, item.getGiftFrom());
                        saved_items.add(pair);
                        ps.addBatch();
                    }

                    ps.executeBatch();
                    System.out.println("Time to save items " + (System.currentTimeMillis() - start));
                    start = System.currentTimeMillis();
                    System.out.println("RIGHT BEFORE EQUIPMENT");
                    try (ResultSet rs = ps.getGeneratedKeys()) {
                        for (Pair<Item, MapleInventoryType> item : saved_items) {  
                            int key = -1;
                            if (rs.next()) {                            
                                key = rs.getInt(1);
                            }

                            if (key == 0) {
                                key = item.getLeft().getInventoryItemId();
                            }

                            worker.batch(item, key, id);
                            MapleInventoryType mit = item.right; 
                            if (mit.equals(MapleInventoryType.EQUIP) || mit.equals(MapleInventoryType.EQUIPPED)) {
                                pse.setInt(1, key);
                                Equip equip = (Equip) item.left;
                                pse.setInt(2, equip.getUpgradeSlots());
                                pse.setInt(3, equip.getLevel());
                                pse.setInt(4, equip.getStr());
                                pse.setInt(5, equip.getDex());
                                pse.setInt(6, equip.getInt());
                                pse.setInt(7, equip.getLuk());
                                pse.setInt(8, equip.getHp());
                                pse.setInt(9, equip.getMp());
                                pse.setInt(10, equip.getWatk());
                                pse.setInt(11, equip.getMatk());
                                pse.setInt(12, equip.getWdef());
                                pse.setInt(13, equip.getMdef());
                                pse.setInt(14, equip.getAcc());
                                pse.setInt(15, equip.getAvoid());
                                pse.setInt(16, equip.getHands());
                                pse.setInt(17, equip.getSpeed());
                                pse.setInt(18, equip.getJump());
                                pse.setInt(19, equip.getVicious());
                                pse.setInt(20, equip.getItemLevel());
                                pse.setInt(21, equip.getItemExp());
                                pse.setInt(22, equip.getRingId());
                                pse.setBoolean(23, equip.hasSkill());
                                pse.addBatch(); 
                            }
                        }
                        pse.executeBatch();
                    }
                }
                worker.executeBatch(id);
            }
            System.out.println("Time to save equipment " + (System.currentTimeMillis() - start));
        } catch (Exception e) {
            LogHelper.GENERAL_EXCEPTION.get().info("ItemFactory saveItems: " + e);
        } finally {
            worker.close();
            lock.unlock();
        }
    }