java.math.BigDecimal cannot be cast to java.lang.String解决方法
从mysql数据库里取decimal(18,2)封装到Map<String,String>中
BigDecimal b = new BigDecimal(resultMap.get("amount"));
b=b.setScale(2, BigDecimal.ROUND_HALF_UP); //四舍五入
在第一行报类型转换异常
解决方法:
Object ob = resultMap.get("amount");
BigDecimal b = new BigDecimal(ob.toString());
b=b.setScale(2, BigDecimal.ROUND_HALF_UP); //四舍五入
java.math.BigDecimal cannot be cast to java.lang.String解决方法的更多相关文章
- 数据转换失败 java.math.BigDecimal cannot be cast to java.lang.String
从接口获取到数据,在转换的时候出现错误:java.math.BigDecimal cannot be cast to java.lang.String 因为一开始用的是使用关键字进行强制转换,后来发现 ...
- 数据转换bug花了半天时间 Java.math.BigDecimal cannot be cast to java.lang.String
从数据库取出一个 Count函数 统计的值 在代码中要转成Integer类型的时候 Integer.parseInt((String)map.get("ID_")) 报了一下错误: ...
- 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 '>= ...
- Java报错:java.math.BigDecimal cannot be cast to java.lang.String
从数据库取数字,转为string,报错: java.math.BigDecimal cannot be cast to java.lang.String 错误代码 Integer.parseInt(( ...
- java.math.BigDecimal cannot be cast to java.lang.Integer
问题来源: 在数据库中查询一个列表的长度时,需要转换为Integer类型,我刚开始直接转就报错了.因为在数据库中用count(*) 聚合函数返回的值类型为BigDecimal,不能直接转换为Integ ...
- 关于 java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.String
今天遇到了这个异常,其实是自己经验欠缺所致.我是通过mybatis查询到数据库传过来的主键,是一个32位的char类型. 代码: //查询总账表的该组织总账记录,包括该条记录的主键id.账户余额Dzz ...
- java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.String错误的解决方法
mmobjectid是在Oracle数据库中对应的是Number类型的,在JavaBean中定义的是Long类型的. List<BigDecimal> mmobjidAllFromMars ...
- java.math.BigDecimal cannot be cast to [Ljava.lang.Object;
从数据库中使用sum函数取出统计值后,放进list中,遍历list的时候强转化成Object是报错. BigDecimal .Integer不是基本类型,是int的包装类,无法把包装当做基本类型来用. ...
- java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.String
http://blog.csdn.net/agileclipse/article/details/17161225 详情请点击链接查看
随机推荐
- excel跨表查询数据
环境:公司部分部门进行商品盘点,店铺经理要求不经过系统进行盘点,全程采用excel表格处理所示: 左图为总表,右图为首饰部门录入的数据 需求:找出盘点差异(即首饰部商品数量是否和 ...
- ES6相关特性(解构赋值)
解构赋值:本质上是一种匹配模式,等号两边的模式相同,则左边的变量可以被赋予对应的值. 注意:null & undefined 不能解构赋值!!! 数组的解构赋值: let [a,[[b],c] ...
- IOS 封装View的fram(X Y W H )
@interface UIView (Extension) @property (nonatomic, assign) CGFloat x; @property (nonatomic, assign) ...
- cityscape分割3类别数据处理
cpp: #include "cv.h" #include "highgui.h" #include <iostream> #include < ...
- Spring boot 集成三种定时任务方式
三种定时任务方式分别为 org.springframework.scheduling.annotation.Scheduled java.util.concurrent.ScheduledExecut ...
- centos7 kvm安装使用
kvm简介 KVM 全称是 Kernel-Based Virtual Machine.也就是说 KVM 是基于 Linux 内核实现的. KVM有一个内核模块叫 kvm.ko,只用于管理虚拟 CPU ...
- sql插入临时表数据的方法
方法有两种,主要看需求. 方法1:定义好临时表的字段和类型.插入对应的值 create table #Tmp --创建临时表#Tmp ( City varchar(), -- Country varc ...
- android design 新控件
转载请标明出处: http://blog.csdn.net/forezp/article/details/51873137 本文出自方志朋的博客 最近在研究android 开发的新控件,包括drawe ...
- jquery操作元素的位置
.offset() 在匹配的元素中,获取第一个元素的当前坐标,或设置每一个元素的坐标,坐标相对于文档. .offset() 这个不接受任何参数. var offset = p.offset(); // ...
- (三)、python运算符和基本数据类型
运算符 1.算数运算: 2.比较运算: 3.赋值运算: 4.逻辑运算: 5.成员运算: 基本数据类型 1.数字 int(整形) # python3里不管数字有多长都叫整形# python2里分为整形和 ...