0

My main code is like this:

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);

And trying to compile there is this error:

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)

By debbuging with printlns the line that leaves my try-catch block is this:

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

Nothing goes after this and everything comes before this.

con is declared before as Connection con = null and URL, USER and PASSWORD beeing normal words for connection:

URL = "jdbc:mysql://localhost:3306/lojanoturno?zeroDateTimeBehavior=convertToNull"

USER = "root" / PASSWORD = "root"

Is this error right in the DriverManager.getConnection() or somehow I got the wrong line using the printlns (I know, not the best usage for this, I also debugged but can't say I master knowing when the program writes the errors messages in the stackTrace).

  • @NathanHughes Why exactly initializePropsFromServer? –  Jun 18 '18 at 00:40
  • 2
    you need to validate whether the driver version, that you are using, is compatible with mysql version that you are using. – gagan singh Jun 18 '18 at 00:56
  • Looks like you have initialised a variable with `Long` while the DB value needs it to be `BigInteger`. Mostly it's the `id` column. I can't see the complete code here, so can't say for sure. It's also possible that you are using a collection like `List` while you should be using `List`. – Kartik Jun 18 '18 at 00:57
  • @gagansingh that's exactly what i had to do. It was using mysql-connector-java-5.123.jar from the NetBeans files and after I deleted and added the one I'm using (my-sql-connector-java-5.1.46-bin.jar) it worked! Thanks a lot!!! –  Jun 18 '18 at 01:14

0 Answers0