Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can ı solve Exception in thread "main" java.lang.ClassCastException solve?

When I remove Connection netbeans say me "You should add Connection cast" but after add, it gives me class cast exception.

How can ı solve this.

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The exception tells all


The DriverManager.getConnection returns a java.mysql.connection or more specifically a com.mysql.cj.jdbc.ConnectionImpl when using Mysql

And you have imported a com.sun.jdi.connect.spi.Connection which is nothing related to


Use the right import and it’ll be good

import com.mysql.cj.jdbc.ConnectionImpl; // REMOVE
import java.mysql.Connection;            // ADD
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading