MySQL随机空字符串作为列值

时间:2016-03-23 03:11:17

标签: java mysql

我一直在为Minecraft服务器整体插件设置MySQL,到目前为止,我已经使用相同的方法成功存储了所有数据。问题是当我想检查是否创建了行时,否则创建它,以某种方式这样做我的行值从null(注意它是一个值为null的字符串)被破坏为空字符串。< / p>

表auchouse包含2个字段。 id int(3)unique和items varchar(21000)default'null'。

这是我从新数据库开始时获得的堆栈跟踪。 以某种方式调用ITEM检查值两次,其中“null”值丢失。会对此提供一些帮助。

    [15:57:11] [Server thread/INFO]: [DivinityRealm] NOT REGISTERED
    [15:57:11] [Server thread/INFO]: [DivinityRealm] VALUE SET FOR IT 1
    [15:57:11] [Server thread/INFO]: [DivinityRealm] VALUE OF ITEM null
    [15:57:11] [Server thread/INFO]: [DivinityRealm] VALUE OF ITEM
    [15:57:11] [Server thread/INFO]: [DivinityRealm] VALUE OF ITEM  NULL CHECK PASS$

[15:57:11] [Server thread/INFO]: [DivinityRealm] ITEMS VALUE

错误开始(DiivinityRealm.java):

AuctionHouse au = null;
int count = 1;
do
{
    au = new AuctionHouse(count);
    au.update();
    for (Player p : Bukkit.getOnlinePlayers()) {
        if(p.getOpenInventory().getTitle().contains("Auction House")
                && Integer.parseInt(p.getOpenInventory().getTitle().split(" ")[2]) == au.getPage())
        {
            p.openInventory(au.getInventory());
        }
    }
    count++;
}while(!new AuctionHouse(count-1).isEmpty());

AuctionHouse.java:

public AuctionHouse(int pageNum)
{
    this.pageNum = pageNum;
    inv = DivinityRealm.getInstance().getServer().createInventory(null, 45, "Auction House " + pageNum)
    /* stuff*/
    register();

    getItems();
}

注册方法(AuctionHouse.java):

private void register()
{
    try {
        PreparedStatement ps = DivinityRealm.connection.prepareStatement(AuctionTable.selectID);
        ps.setInt(1, pageNum);
        ResultSet rs = ps.executeQuery();
        if(!rs.next()){
            DivinityRealm.getInstance().getLogger().info("NOT REGISTERED");
            PreparedStatement state = DivinityRealm.connection.prepareStatement(AuctionTable.insertEntryAllInfo);
            state.setInt(1, pageNum);
            state.executeUpdate();
            rs = ps.executeQuery();
            rs.next();
            DivinityRealm.getInstance().getLogger().log(Level.INFO, "VALUE SET FOR IT {0}", rs.getString(1));
        }
    } catch (SQLException ex) {
        Logger.getLogger(AuctionHouse.class.getName()).log(Level.SEVERE, "Couldn't register AucHouse", ex);
    }  
}

getItems()方法(AuctionHouse.java):

private void getItems()
{
    try
    {
        PreparedStatement ps = DivinityRealm.connection.prepareStatement(AuctionTable.selectItems);
        ps.setInt(1, pageNum);
        ResultSet rs = ps.executeQuery();
        if(rs.next()){
            DivinityRealm.getInstance().getLogger().log(Level.INFO, "VALUE OF ITEM {0}", rs.getString(1));
            if(rs.getString(1).equals("null")){
                return;
            }
            DivinityRealm.getInstance().getLogger().log(Level.INFO, "VALUE OF ITEM {0} NULL CHECK PASSED", rs.getString(1));
            for(ItemStack item : deserialize(rs.getString(1)))
            {
                inv.addItem(item);
            }
        }
    }catch (SQLException ex) {
        Logger.getLogger(AuctionHouse.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
    }
}

0 个答案:

没有答案