Search code examples
javamysqljdbcjarprepared-statement

cannot find symbol PreparedStatement after JAR upgrade


I just upgraded mysql jdbc connection JAR (from mysql-connector-java-5.0.5.jar to mysql-connector-java-8.0.19.jar) and the project started showing error for import statements:

import com.mysql.jdbc.PreparedStatement;

java: cannot find symbol
  symbol:   class PreparedStatement
  location: class package.ClassName 

Where to find the location or package for PreparedStatement in new jar file or is it replaced with any other class in new JAR?

enter image description here


Solution

  • Try to replace it with:

    import java.sql.PreparedStatement;
    

    Using com.mysql.jdbc.PreparedStatement is specific to mysql, and should not be imported directly.

    So unless you need MySQL specific features, it's always better to use the interface java.sql.PreparedStatement that is database independent. See also this.