DriverManager.getConnection()链接,报java.math.BigInteger cannot be cast to java.lang.Long

错误描述:

DriverManager.getConnection(url, user, password);的时候,报java.math.BigInteger cannot be cast to java.lang.Long错误

解决流程:

百度一顿没什么结果,Debug发现是在ConnectionImpl.java下int collationIndex = indexEntry.getKey().intValue()的时候,indexEntry=1-big5,1是BigInteger类型,这怎么转化,一脸迷茫。

然后自认为是是MySQL编码配置问题,我用的是免安装版mysql,卸载快,重装,然并卵。

最后抱着试一试的态度,把链接mysql——jar包换成最新,发现连上了,啊啊啊~~~~~~~~

原来是jar包版本和mysql版本不一致(mysql-connector-java-5.1.26.jar 换成了mysql-connector-java-5.1.46.jar)

 其实 也不明白这两个版本差在哪,感觉都是5.1下的,应该差不多把,就这样把。

2018/4/17

阅读更多

java.math.BigInteger cannot be cast to com.labmanager.fw.data.bo.Lab

02-23

[code=java]rnpackage com.labmanager.fw.JUNIT;rnrnimport java.util.ArrayList;rnimport java.util.Iterator;rnimport java.util.List;rnrnimport org.hibernate.SQLQuery;rnimport org.hibernate.Session;rnimport org.hibernate.Transaction;rnrnimport com.labmanager.fw.data.bo.Lab;rnimport com.labmanager.fw.util.HibernateSessionFactory;rnrnpublic class PageDeviceTestrnrn public List getResultCount(String table)rn Session session=HibernateSessionFactory.getSession();rn Transaction ts=session.beginTransaction();rn List list=new ArrayList();rn String sql="select count(*) from "+table+" where id > 0";rn tryrn ts.begin();rn SQLQuery sqlQuery=session.createSQLQuery(sql); rn list=sqlQuery.list();rn ts.commit();rn System.out.println("查询到数据"+list.get(0).toString()+"条");rn catch(Exception e)rn ts.rollback();rn e.printStackTrace();rn finallyrn HibernateSessionFactory.closeSession();rn rn return list;rn rn public void dispaly()rn List list=new ArrayList();rn list=this.getResultCount("tblab");rn Iterator it=list.iterator();rn while(it.hasNext())rn System.out.println(((Lab)it.next()).getName());rn rn rn public static void main(String[] args)rn new PageDeviceTest().dispaly(); rn rnrnrnrn[/code]rnrnrn&rnrnConsole输出:rnrn查询到数据20条rnException in thread "main" java.lang.ClassCastException: java.math.BigInteger cannot be cast to com.labmanager.fw.data.bo.Labrn at com.labmanager.fw.JUNIT.PageDeviceTest.dispaly(PageDeviceTest.java:40)rn at com.labmanager.fw.JUNIT.PageDeviceTest.main(PageDeviceTest.java:44)rnrnrn&rnLab类是Hibernate inverse 生成的。rn主键类型为Shortrn配置文件如下rnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrnrn错误实在搞不明白。网上也看了搞了很久没辙了。。。

没有更多推荐了,返回首页