ClassCastException:java.math.BigInteger无法在DriverManager.getConnection()上强制转换为java.lang.Long

时间:2018-06-17 23:54:59

标签: java

我的主要代码是这样的:

Fisica f = new Fisica();
f.setNome("Harry Deitel");
f.setCpf("123.456.789-00");
f.setDataNascimento(new Date());
...
ClienteFisicoService cfs = FabricaService.getClienteFisicoService();
boolean b = cfs.salvar(f);
System.out.println("Value: " + b);

尝试编译时出现此错误:

java.sql.SQLException: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
at com.mysql.jdbc.ConnectionImpl.buildCollationMapping(ConnectionImpl.java:1062)
at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3556)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2513)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2283)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:822)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:404)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at br.unesp.rc.s4lsa.utils.FabricaConexao.getConexao(FabricaConexao.java:20)
at br.unesp.rc.s4lsa.dao.ClienteFisicoDAOImpl.salvar(ClienteFisicoDAOImpl.java:20)
at br.unesp.rc.s4lsa.service.ClienteFisicoServiceImpl.salvar(ClienteFisicoServiceImpl.java:18)
at demo.Main.main(Main.java:32)

通过使用printlns进行重新划分,离开try-catch块的行是:

 con = DriverManager.getConnection(URL, USER, PASSWORD);

此后没有任何事情发生,一切都在此之前。

con之前声明为Connection con = null且URL,USER和PASSWORD正在连接正常单词:

URL =&#34; jdbc:mysql:// localhost:3306 / lojanoturno?zeroDateTimeBehavior = convertToNull&#34;

USER =&#34; root&#34; / PASSWORD =&#34; root&#34;

这个错误在DriverManager.getConnection()中是否正确,或者我使用printlns得到了错误的行(我知道,这不是最好的用法,我也调试了但是不能说我掌握了知道什么时候程序将错误消息写入stackTrace)。

0 个答案:

没有答案