1、数据库返回的类型要与java的类型匹配
public List<BigInteger> getMouldIdsbySupplierName(String supplierName) {
Session session = sessionFactory.getCurrentSession();
String sql = "select TT_MOULD_MANAGE_ID FROM BOM.TT_MOULD_MANAGE\r" +
"where tt_part_id in (\r" +
"select DISTINCT a.tt_part_id \r" +
"from PROCUREMENT.TT_NOMINATION_RECORD a \r" +
"left join ENTERPRISE.TM_SUPPLIER b on a.tm_supplier_id = b.tm_supplier_id\r" +
"left join CORE.TS_ORGANIZATION c on b.ts_organization_id = c.ts_organization_id\r" +
"left join PROJECT.TT_PART_TOOLING d on a.tt_part_id = d.tt_part_id\r" +
"left join PROJECT.TT_TOOLING e on d.tt_tooling_id = e.tt_tooling_id\r" +
"where c.org_name like '%"+ supplierName +"%' and \r" +
"e.tooling_type in (1,2,3,16,30))";
@SuppressWarnings("unchecked")
List<BigInteger> partIds = session .createSQLQuery(sql.toString()).list();
return partIds;
}
这里只能用BigInteger(java.math.BigInteger),如果用String、Integer、Long等类型均会报错)。
跨坑方法:一般控制台会输出错误信息,如果没有输出错误信息即是被捕获了。
2、类型转换转换异常
Long[] newLong = new Long[mouldIds.size()];
for(int i = 0;i<mouldIds.size();i++){
String str= mouldIds.get(i).toString();
newLong[i] = Long.valueOf(str);
}
一般各种类型之间都是可以转换的。
万能的转换方式,就是先转成String再转成其他类型。