@Jfinal 老大提供的解决方法

当数据库字段为 int 型(有符号int型),但是如果在 sql 中使用了某些函数,jdbc 会自动转型为 long,例如:select sum(money) from account where accountId = 123。这个行为是 jdbc自动做的,目的是为了防止数据溢出,因为在本例中 money 本来是 int 型,但是 sum(money) 以后很可能数值会超过 java Integer.MAX_VALUE值。另一种 int 自动转 long 型是因为字段使用是无符号 int 型,这两种自动转型都是 jdbc 自动的,jfinal 未做任何干预。至于 int 型可以使用 getStr 读取出来,那必定是值为 null, 否则肯定会抛出类型转换异常。

解决的办法通常两个:

1:预知可能的转型,使用正确的类型变量去接收值,例如用 Long变量去接收 select sum(xxx)值。

2:使用 getNumber(attr).intValue() 确切一定得到 Integer 值,或者使用 getNumber(attr).longValue() 确切一定得到 Long 值。

对于jfinal中java.lang.Long cannot be cast to java.lang.Integer的解决方法的更多相关文章

  1. java.lang.ClassCastException: java.lang.Short cannot be cast to java.lang.String(Short类型无法强转成String类型)

    有一行Java代码如下: String code1 = (String)qTable1.getValueAt(i, 0); 这是一个Java的图形界面获取表格中值的代码,其中qTable1.getVa ...

  2. 数据转换bug花了半天时间 Java.math.BigDecimal cannot be cast to java.lang.String

    从数据库取出一个 Count函数 统计的值 在代码中要转成Integer类型的时候 Integer.parseInt((String)map.get("ID_")) 报了一下错误: ...

  3. java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer

    hibernate查询结果条数集 原写法: Integer count = (Integer )session.createQuery(hql).uniqueResult(); 报错:java.lan ...

  4. MySQL分段统计SQL写法 与 Mybatis 异常 java.math.BigDecimal cannot be cast to java.lang.Integer

    mysql> select end) as '<60', end) as '60~69', end) as '70~79', end) as '80~89', end) as '>= ...

  5. ArrayMap java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Object[]

    错误堆栈: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Object[] at android ...

  6. 连接Mysql时出现java.math.BigInteger cannot be cast to java.lang.Long问题

    今天遇见这样一个坑.在连接数据库进行查询数据时,大家可能会遇见这样一个问题:java.math.BigInteger cannot be cast to java.lang.Long,然后去检查代码中 ...

  7. java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.String

    问题背景:从前端传来的json字符串中取某些值,拼接成json格式入参调外部接口. 报如下错: java.lang.ClassCastException: java.util.HashMap cann ...

  8. Spring boot启动时报 java.sql.SQLException: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long错误

    Spring boot启动时报 java.sql.SQLException: java.lang.ClassCastException: java.math.BigInteger cannot be ...

  9. java.lang.Long cannot be cast to java.lang.Integer解决办法

    情景: mybatis连接oracle 报错: 测试增的时候,报错 Java.lang.Long cannot be cast to  java.lang.Integer:删改没有报错. 排查过程: ...

  10. [记录]java.math.biginteger cannot be cast to java.lang.long

    可以直接使用BigInteger类型进行接收, BigInteger id = (BigInteger)QueryRunner(conn,"SELECT LAST_INSERT_ID&quo ...

随机推荐

  1. UI进阶 数据处理之文件读写

    目录: 1-------沙盒机制(SandBox) 2-------简单对象的读写(I/O)操作 3-------复杂对象的读写(I/O)操作 一.沙盒机制(SandBox) 什么是沙盒:每个iOS应 ...

  2. jQuery的遍历方法

    1.jQuery中的map使用方法 <!DOCTYPE html> <html> <head> <style>p { color:red; }</ ...

  3. MSSQLSERVER数据库- 触发器

    参考了别人写的文章,我删除掉一些废话,只看一些我想看的信息.整理了一下,记录在这里,方便以后查阅! 1.当触发INSERT触发器时,新的数据行就会被插入到触发器表和inserted表中. 2.当触发d ...

  4. ECshop数据库的访问统计和管理员日志的清空

    ECshop是个不错的系统,但是它有一定漏洞,若是访问量巨大的话,大量的访问统计代码会存入数据库的ecs_stats表中,甚至几天就可以达到几百兆,严重的网站直接就崩溃了.数据备份的时候也有很多不便, ...

  5. Swift基本语法及与OC比较之二

    //MARK:-----------------控制流----------------- //MARK: 1.for - in 循环 ,不用声明Value类型 //for value in 1...6 ...

  6. 实例:ABAP Tree Control 使用与ALV Grid对象关联

    Tree Control 是最常用的Windows控件之一,在其他语言中成为"Tree View"等,ABAP的 Tree Contiol 能实现类似的功能. 本文主要介绍一下内容 ...

  7. 【转】bt协议的详细分析

    转自:https://baoz.net/bt-protocol/ 一 BT系统的组成结构 1 普通的Web服务器:        例如Apache或IIS服务器 2 一个静态的种子文件:     即. ...

  8. 获取windows版本信息

    procedure TForm1.Button1Click(Sender: TObject); Var     OSVI:OSVERSIONINFO; begin     OSVI.dwOSversi ...

  9. [Practical Git] Remove unnecessary git tracking with .gitignore files

    Most projects have automatically generated files or folders from the operating system, applications, ...

  10. [Bootstrap] 7. Working Herader

    <header class="navbar navbar-default navbar-static-top"> <div class="contain ...