【发布时间】:2012-12-02 12:11:26
【问题描述】:
代码:
public int getLastGotKill()
{
Connection con = null;
int last_pvp_time = 0;
try
{
con = L2DatabaseFactory.getInstance().getConnection(false);
PreparedStatement statement;
statement = con.prepareStatement("select last_got_kill from characters where obj_Id=?");
statement.setInt(1, getObjectId());
ResultSet rset = statement.executeQuery();
while(rset.next())
{
last_pvp_time = rset.getInt("last_got_kill");
_log.info("last pvp time is : " + last_pvp_time);
}
rset.close();
rset = null;
statement.close();
statement = null;
}
catch(Exception e)
{
if(Config.ENABLE_ALL_EXCEPTIONS)
e.printStackTrace();
}
finally
{
CloseUtil.close(con);
con = null;
}
return last_pvp_time;
}
所以当我调用此函数时,它会进入try{} 内的while loop,但是当我尝试打印所选列的值时,它会打印 0,因此它会返回 0...
字符表中的last_got_kill column 是bigint(20) 类型
我可以看到该列中有一个数字。 4294967295 是
但为什么我总是得到 0 回来?
【问题讨论】:
-
4294967295 十六进制是 0xffffffff ,即 -1 是二进制补码。它也大于可以存储在有符号整数中的最大值。看起来你在插入数据时弄乱了数据。
-
如果查询没有返回任何行,那么你的方法将返回 0,你确定你的查询实际上是在选择一行吗?
-
@MarkByers 我只是以毫秒为单位存储一个日期并想要取回它
-
@MarkRotteveel 它返回行,因为我可以在控制台中看到 _log.info() 消息,也只返回 0
-
@fxuser:您不能将自纪元以来的毫秒数存储在
int中。数字太大了。当您使用太小的类型插入数据时,您可能严重破坏了数据。您可能必须从数据的干净副本开始,然后将其全部重新插入。不幸的是,如果您没有备份,它可能会永远消失。
标签: java mysql sql database select